diff --git a/src/dev.rs b/src/dev.rs new file mode 100644 index 0000000..b342774 --- /dev/null +++ b/src/dev.rs @@ -0,0 +1,8 @@ +pub fn log(function: &F, message: &str) { + eprintln!( + "{:?} [{}] {message}", + crate::ONSET.elapsed(), + std::any::type_name_of_val(function).replace("en::", ""), + ); +} + diff --git a/src/handlers/fixed.rs b/src/handlers/fixed.rs index 59d7eb3..f215c4f 100644 --- a/src/handlers/fixed.rs +++ b/src/handlers/fixed.rs @@ -6,6 +6,7 @@ use axum::{ use crate::formats::{Format, populate_graph, serialize_graph}; use crate::handlers; +#[expect(clippy::unused_async)] pub async fn file(file_path: &str, content_type: &str) -> Response { let content = match std::fs::read(file_path) { Ok(s) => s, @@ -20,21 +21,24 @@ pub async fn file(file_path: &str, content_type: &str) -> Response { if let Ok(header_value) = HeaderValue::from_str(content_type) { if let Some(h) = response.headers_mut().insert(header, header_value) { - eprintln!( - "[file_handler] Overwrote existing header {h:?} \ - because a header for the same key existed" + crate::dev::log( + &file, + &format!("Overwrote existing header {h:?} because a header for \ + the same key existed") ); } } else { - eprintln!( - "[file_handler] Failed to create content type \ - header value from {content_type}" + crate::dev::log( + &file, + &format!("[file_handler] Failed to create content type \ + header value from {content_type}") ); } response } +#[expect(clippy::unused_async)] pub async fn serial(format: &Format) -> Response { let graph = populate_graph(); let body = serialize_graph(format, &graph); diff --git a/src/handlers/navigation.rs b/src/handlers/navigation.rs index 323c4cc..cdfdec7 100644 --- a/src/handlers/navigation.rs +++ b/src/handlers/navigation.rs @@ -7,6 +7,7 @@ use axum::{ use crate::{formats::populate_graph, types::Node, handlers}; +#[expect(clippy::unused_async)] pub async fn nexus(template: &str) -> Response { let mut context = tera::Context::new(); let graph = populate_graph(); diff --git a/src/handlers/raw.rs b/src/handlers/raw.rs index 9049268..bb9c6aa 100644 --- a/src/handlers/raw.rs +++ b/src/handlers/raw.rs @@ -18,16 +18,17 @@ pub fn make_response( if let Some(overwritten) = response.headers_mut().insert(header.0.clone(), wrapped) { - eprintln!( - "[make_response] Overwrote header {overwritten:?} \ + crate::dev::log( + &make_response, + &format!("Overwrote header {overwritten:?} \ because another for key {} already existed", - header.0 + header.0) ); } } else { - eprintln!( - "[make_response] Failed to wrap header value {}", - header.1 + crate::dev::log( + &make_response, + &format!("Failed to wrap header value {}", header.1) ); } } diff --git a/src/main.rs b/src/main.rs index be1466d..eadd325 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ use formats::Format; mod formats; mod types; mod handlers; +mod dev; static ONSET: std::sync::LazyLock = std::sync::LazyLock::new(std::time::Instant::now); @@ -60,8 +61,11 @@ async fn main() { match axum::serve(listener, app).await { Ok(()) => (), Err(e) => { - eprintln!( - "Failed to serve application with axum::serve: {e:#?}" + dev::log( + &main, + &format!( + "Failed to serve application with axum::serve: {e:#?}" + ) ); std::process::exit(1); },