From 20f4ae06586f034053c121416c54abc9790fb19b Mon Sep 17 00:00:00 2001 From: Adrian Hedqvist Date: Sun, 2 Apr 2023 15:27:06 +0200 Subject: [PATCH] cargo fmt --- src/handlers/mod.rs | 9 ++++++--- src/handlers/posts.rs | 5 ++--- src/handlers/tags.rs | 3 +-- src/main.rs | 13 ++++++------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 53ae3b7..4af9194 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -2,7 +2,7 @@ use axum::{ body, extract::State, middleware::Next, - response::{Html, IntoResponse, Response, Redirect}, + response::{Html, IntoResponse, Response}, routing::get, Router, }; @@ -10,7 +10,7 @@ use hyper::{header::CONTENT_TYPE, Request, StatusCode}; use lazy_static::lazy_static; use prometheus::{opts, Encoder, IntCounterVec, TextEncoder}; use std::sync::Arc; -use tracing::{info_span, instrument, log::*, Instrument}; +use tracing::{instrument, log::*}; use crate::{AppState, WebsiteError}; @@ -37,7 +37,10 @@ pub fn routes(state: &Arc) -> Router> { .layer(axum::middleware::from_fn(metrics_middleware)) .route("/healthcheck", get(healthcheck)) .route("/metrics", get(metrics)) - .route_service("/posts/:slug/*path", tower_http::services::ServeDir::new("./")) + .route_service( + "/posts/:slug/*path", + tower_http::services::ServeDir::new("./"), + ) .route_service("/static/*path", tower_http::services::ServeDir::new("./")) } diff --git a/src/handlers/posts.rs b/src/handlers/posts.rs index 2c7e10a..da6252f 100644 --- a/src/handlers/posts.rs +++ b/src/handlers/posts.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use axum::{ extract::{Path, State}, - response::{Html, Redirect, IntoResponse}, + response::{Html, Redirect}, routing::get, Router, }; @@ -87,8 +87,7 @@ pub async fn redirect( ) -> Result { if state.posts.contains_key(&slug) { Ok(Redirect::permanent(&format!("/posts/{slug}/"))) - } - else { + } else { Err(WebsiteError::NotFound) } } diff --git a/src/handlers/tags.rs b/src/handlers/tags.rs index de250c4..04c6df8 100644 --- a/src/handlers/tags.rs +++ b/src/handlers/tags.rs @@ -72,8 +72,7 @@ pub async fn redirect( ) -> Result { if state.tags.contains_key(&slug) { Ok(Redirect::permanent(&format!("/tags/{slug}/"))) - } - else { + } else { Err(WebsiteError::NotFound) } } diff --git a/src/main.rs b/src/main.rs index 84506c1..f5ef2ac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,9 +37,11 @@ async fn main() -> Result<()> { let app = handlers::routes(&state) .layer(CorsLayer::permissive()) .layer(CompressionLayer::new()) - .layer(tower_http::trace::TraceLayer::new_for_http() - .make_span_with(make_span) - .on_response(on_response)) + .layer( + tower_http::trace::TraceLayer::new_for_http() + .make_span_with(make_span) + .on_response(on_response), + ) .with_state(state); info!("Now listening at http://localhost:8180"); @@ -71,10 +73,7 @@ fn make_span(request: &Request) -> Span { .map(|mp| mp.as_str()) .unwrap_or_default(); let method = request.method().as_str(); - let target = uri - .path_and_query() - .map(|p| p.as_str()) - .unwrap_or_default(); + let target = uri.path_and_query().map(|p| p.as_str()).unwrap_or_default(); let name = format!("{method} {route}");