Skip to content

Commit 375a706

Browse files
committed
style: fix formatting
1 parent 65f4f24 commit 375a706

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

crates/asw-cli/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ fn main() -> Result<()> {
254254
let rt = tokio::runtime::Runtime::new()?;
255255
rt.block_on(async {
256256
// Create server state (graph not loaded yet)
257-
let state = std::sync::Arc::new(asw_serve::state::ServerState::new(graph_path, api_key));
257+
let state =
258+
std::sync::Arc::new(asw_serve::state::ServerState::new(graph_path, api_key));
258259

259260
let app = asw_serve::api::create_router(state.clone());
260261
let listener = tokio::net::TcpListener::bind(&listen).await?;

crates/asw-serve/src/api.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,7 @@ async fn api_key_middleware(
149149
req: Request,
150150
next: Next,
151151
) -> Result<axum::response::Response, (StatusCode, Json<ErrorResponse>)> {
152-
let provided = req
153-
.headers()
154-
.get("X-Api-Key")
155-
.and_then(|v| v.to_str().ok());
152+
let provided = req.headers().get("X-Api-Key").and_then(|v| v.to_str().ok());
156153

157154
match provided {
158155
Some(key) if key.as_bytes().ct_eq(state.api_key().as_bytes()).into() => {
@@ -174,7 +171,10 @@ pub fn create_router(state: Arc<ServerState>) -> Router {
174171
let protected = Router::new()
175172
.route("/route", get(route_handler))
176173
.route("/info", get(info_handler))
177-
.layer(middleware::from_fn_with_state(state.clone(), api_key_middleware));
174+
.layer(middleware::from_fn_with_state(
175+
state.clone(),
176+
api_key_middleware,
177+
));
178178

179179
Router::new()
180180
.route("/health", get(health_handler))
@@ -277,7 +277,9 @@ mod tests {
277277
.unwrap();
278278
let resp = app.oneshot(req).await.unwrap();
279279
assert_eq!(resp.status(), HyperStatus::UNAUTHORIZED);
280-
let body = axum::body::to_bytes(resp.into_body(), usize::MAX).await.unwrap();
280+
let body = axum::body::to_bytes(resp.into_body(), usize::MAX)
281+
.await
282+
.unwrap();
281283
let json: serde_json::Value = serde_json::from_slice(&body).unwrap();
282284
assert_eq!(json, serde_json::json!({"error": "unauthorized"}));
283285
}

crates/asw-serve/src/state.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ pub struct ServerState {
1111

1212
impl ServerState {
1313
pub fn new(graph_path: String, api_key: String) -> Self {
14-
assert!(!api_key.trim().is_empty(), "API key must not be empty or whitespace-only");
14+
assert!(
15+
!api_key.trim().is_empty(),
16+
"API key must not be empty or whitespace-only"
17+
);
1518
Self {
1619
inner: tokio::sync::RwLock::new(None),
1720
graph_path,

0 commit comments

Comments
 (0)