Apply formatting and satisfy lints

This commit is contained in:
Juno Takano 2025-12-13 16:32:20 -03:00
commit 82f1f0c63c
5 changed files with 35 additions and 18 deletions

View file

@ -5,4 +5,3 @@ pub fn log<F>(function: &F, message: &str) {
std::any::type_name_of_val(function).replace("en::", ""),
);
}

View file

@ -6,7 +6,6 @@ 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<Body> {
let content = match std::fs::read(file_path) {
Ok(s) => s,
@ -23,15 +22,19 @@ pub async fn file(file_path: &str, content_type: &str) -> Response<Body> {
if let Some(h) = response.headers_mut().insert(header, header_value) {
crate::dev::log(
&file,
&format!("Overwrote existing header {h:?} because a header for \
the same key existed")
&format!(
"Overwrote existing header {h:?} because a header for \
the same key existed"
),
);
}
} else {
crate::dev::log(
&file,
&format!("[file_handler] Failed to create content type \
header value from {content_type}")
&format!(
"Failed to create content type \
header value from {content_type}"
),
);
}

View file

@ -20,15 +20,17 @@ pub fn make_response(
{
crate::dev::log(
&make_response,
&format!("Overwrote header {overwritten:?} \
&format!(
"Overwrote header {overwritten:?} \
because another for key {} already existed",
header.0)
header.0
),
);
}
} else {
crate::dev::log(
&make_response,
&format!("Failed to wrap header value {}", header.1)
&format!("Failed to wrap header value {}", header.1),
);
}
}

View file

@ -19,6 +19,7 @@ pub(super) fn by_filename(
make_response(&body, status_code, &[(header::CONTENT_TYPE, "text/html")])
}
#[expect(clippy::unused_async)]
pub async fn fixed(name: &str) -> Response<Body> {
by_filename(name, &tera::Context::new(), 500, None, false)
}

View file

@ -28,24 +28,36 @@ async fn main() {
if trace.status() == std::backtrace::BacktraceStatus::Captured {
eprintln!("\n Stack trace:\n{trace:#?}");
}
}));
let app = Router::new()
.route("/", get(|| handlers::navigation::nexus("index.html"))
.post(handlers::navigation::search))
.route("/graph/toml", get(|| handlers::fixed::serial(&Format::Toml)))
.route("/graph/json", get(|| handlers::fixed::serial(&Format::Json)))
.route(
"/",
get(|| handlers::navigation::nexus("index.html"))
.post(handlers::navigation::search),
)
.route(
"/graph/toml",
get(|| handlers::fixed::serial(&Format::Toml)),
)
.route(
"/graph/json",
get(|| handlers::fixed::serial(&Format::Json)),
)
.route(
"/static/style.css",
get(|| handlers::fixed::file("./static/style.css", "text/css")),
)
.route(
"/static/favicon.svg",
get(|| handlers::fixed::file("./static/favicon.svg", "image/svg+xml")),
get(|| {
handlers::fixed::file("./static/favicon.svg", "image/svg+xml")
}),
)
.route(
"/node/{node_id}",
get(handlers::graph::node).post(handlers::graph::node),
)
.route("/node/{node_id}", get(handlers::graph::node)
.post(handlers::graph::node))
.route("/tree", get(|| handlers::navigation::nexus("tree.html")))
.route("/about", get(|| handlers::template::fixed("about.html")))
.route(
@ -65,7 +77,7 @@ async fn main() {
&main,
&format!(
"Failed to serve application with axum::serve: {e:#?}"
)
),
);
std::process::exit(1);
},