Skip to content

Commit

Permalink
Format rust code with new style (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
SKTT1Ryze authored Jun 29, 2024
1 parent 0dbb3c7 commit 4ab3bb6
Show file tree
Hide file tree
Showing 123 changed files with 2,614 additions and 1,455 deletions.
5 changes: 3 additions & 2 deletions clash/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ fn main() {
.to_string();

if !Path::new(&file).exists() {
// TODO: offer a internal default config, to compatible with clash behavior
// TODO: offer a internal default config, to compatible with clash
// behavior
panic!("config file not found: {}", file);
}
if cli.test_config {
Expand All @@ -54,7 +55,7 @@ fn main() {
exit(0);
}
Err(e) => {
eprintln!(" configuration file {} test failed: {}", file, e);
eprintln!("configuration file {} test failed: {}", file, e);
exit(1);
}
}
Expand Down
9 changes: 7 additions & 2 deletions clash_lib/src/app/api/handlers/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ async fn update_configs(
.into_response(),
}
}
(None, None) => (StatusCode::BAD_REQUEST, "no path or payload provided").into_response(),
(None, None) => {
(StatusCode::BAD_REQUEST, "no path or payload provided").into_response()
}
}
}

Expand Down Expand Up @@ -179,7 +181,10 @@ async fn patch_configs(
Json(payload): Json<PatchConfigRequest>,
) -> impl IntoResponse {
if payload.allow_lan.is_some() {
warn!("setting allow_lan doesn't do anything. please set bind_address to a LAN address instead.");
warn!(
"setting allow_lan doesn't do anything. please set bind_address to a \
LAN address instead."
);
}

let mut inbound_manager = state.inbound_manager.lock().await;
Expand Down
13 changes: 10 additions & 3 deletions clash_lib/src/app/api/handlers/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use std::sync::Arc;

use axum::{
body::Body,
extract::{ws::Message, FromRequest, Path, Query, Request, State, WebSocketUpgrade},
extract::{
ws::Message, FromRequest, Path, Query, Request, State, WebSocketUpgrade,
},
response::IntoResponse,
routing::{delete, get},
Json, Router,
Expand Down Expand Up @@ -72,7 +74,10 @@ async fn get_connections(
break;
}

tokio::time::sleep(tokio::time::Duration::from_secs(interval.unwrap_or(1))).await;
tokio::time::sleep(tokio::time::Duration::from_secs(
interval.unwrap_or(1),
))
.await;
}
})
}
Expand All @@ -86,7 +91,9 @@ async fn close_connection(
format!("connection {} closed", id).into_response()
}

async fn close_all_connection(State(state): State<ConnectionState>) -> impl IntoResponse {
async fn close_all_connection(
State(state): State<ConnectionState>,
) -> impl IntoResponse {
let mgr = state.statistics_manager;
mgr.close_all().await;
"all connections closed".into_response()
Expand Down
18 changes: 10 additions & 8 deletions clash_lib/src/app/api/handlers/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ use std::{collections::HashMap, sync::Arc, time::Duration};

use axum::{
extract::{Path, Query, State},
http::Request,
http::StatusCode,
http::{Request, StatusCode},
middleware::{self, Next},
response::{IntoResponse, Response},
routing::get,
Extension, Router,
};
use serde::Deserialize;

use crate::app::{
api::AppState, outbound::manager::ThreadSafeOutboundManager,
remote_content_manager::providers::proxy_provider::ThreadSafeProxyProvider,
use crate::{
app::{
api::AppState, outbound::manager::ThreadSafeOutboundManager,
remote_content_manager::providers::proxy_provider::ThreadSafeProxyProvider,
},
proxy::AnyOutboundHandler,
};
use crate::proxy::AnyOutboundHandler;
#[derive(Clone)]
struct ProviderState {
outbound_manager: ThreadSafeOutboundManager,
Expand Down Expand Up @@ -59,8 +60,9 @@ async fn get_providers(State(state): State<ProviderState>) -> impl IntoResponse
for (name, p) in outbound_manager.get_proxy_providers() {
let p = p.read().await;
let proxies = p.proxies().await;
let proxies =
futures::future::join_all(proxies.iter().map(|x| outbound_manager.get_proxy(x)));
let proxies = futures::future::join_all(
proxies.iter().map(|x| outbound_manager.get_proxy(x)),
);
let mut m = p.as_map().await;
m.insert("proxies".to_owned(), Box::new(proxies.await));
providers.insert(name, m);
Expand Down
3 changes: 2 additions & 1 deletion clash_lib/src/app/api/handlers/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use serde::Deserialize;

use crate::{
app::{
api::AppState, outbound::manager::ThreadSafeOutboundManager, profile::ThreadSafeCacheFile,
api::AppState, outbound::manager::ThreadSafeOutboundManager,
profile::ThreadSafeCacheFile,
},
proxy::AnyOutboundHandler,
};
Expand Down
8 changes: 2 additions & 6 deletions clash_lib/src/app/api/middlewares/auth.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use axum::extract::Query;
use axum::http::Request;
use axum::{body::Body, response::Response};
use axum::{body::Body, extract::Query, http::Request, response::Response};
use futures::future::BoxFuture;

use serde::Deserialize;
Expand Down Expand Up @@ -54,11 +52,9 @@ where
S: Service<Request<Body>, Response = Response> + Send + 'static,
S::Future: Send + 'static,
{
type Response = S::Response;

type Error = S::Error;

type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
type Response = S::Response;

fn poll_ready(
&mut self,
Expand Down
30 changes: 15 additions & 15 deletions clash_lib/src/app/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
use std::net::SocketAddr;
use std::path::PathBuf;
use std::sync::Arc;
use std::{net::SocketAddr, path::PathBuf, sync::Arc};

use axum::{response::Redirect, routing::get, Router};

use http::header;
use http::Method;
use http::{header, Method};
use tokio::sync::{broadcast::Sender, Mutex};
use tower::ServiceBuilder;
use tower_http::cors::{Any, CorsLayer};
use tower_http::services::ServeDir;
use tower_http::trace::TraceLayer;
use tower_http::{
cors::{Any, CorsLayer},
services::ServeDir,
trace::TraceLayer,
};
use tracing::{error, info};

use crate::{config::internal::config::Controller, GlobalState, Runner};

use super::dispatcher::StatisticsManager;
use super::dns::ThreadSafeDNSResolver;
use super::logging::LogEvent;
use super::profile::ThreadSafeCacheFile;
use super::{
dispatcher, inbound::manager::ThreadSafeInboundManager,
outbound::manager::ThreadSafeOutboundManager, router::ThreadSafeRouter,
dispatcher, dispatcher::StatisticsManager, dns::ThreadSafeDNSResolver,
inbound::manager::ThreadSafeInboundManager, logging::LogEvent,
outbound::manager::ThreadSafeOutboundManager, profile::ThreadSafeCacheFile,
router::ThreadSafeRouter,
};

mod handlers;
Expand Down Expand Up @@ -104,7 +101,10 @@ pub fn get_api_runner(
if let Some(external_ui) = controller_cfg.external_ui {
app = app
.route("/ui", get(|| async { Redirect::to("/ui/") }))
.nest_service("/ui/", ServeDir::new(PathBuf::from(cwd).join(external_ui)));
.nest_service(
"/ui/",
ServeDir::new(PathBuf::from(cwd).join(external_ui)),
);
}

let listener = tokio::net::TcpListener::bind(&bind_addr).await.unwrap();
Expand Down
Loading

0 comments on commit 4ab3bb6

Please sign in to comment.