From 982a642d17b20b68c28cf378b8e4598d56f792fc Mon Sep 17 00:00:00 2001 From: Adrian Hedqvist Date: Mon, 5 Sep 2022 00:05:24 +0200 Subject: [PATCH] cargo fix & fmt --- src/handlers/mod.rs | 3 --- src/handlers/posts.rs | 13 +++++-------- src/main.rs | 39 +++++++++++++++++++++------------------ 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index bb89428..92f21f7 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -3,12 +3,9 @@ use std::sync::Arc; use tracing::log::*; use axum::{ - extract::Path, response::{Html, IntoResponse, Response}, - http::{StatusCode, Uri}, Extension, }; -use pulldown_cmark::{html, Options, Parser}; use crate::State; diff --git a/src/handlers/posts.rs b/src/handlers/posts.rs index 8b14880..34a3227 100644 --- a/src/handlers/posts.rs +++ b/src/handlers/posts.rs @@ -1,16 +1,13 @@ use std::sync::Arc; -use axum::{extract::Path, Extension, response::Html}; -use pulldown_cmark::{Options, Parser, html}; +use axum::{extract::Path, response::Html, Extension}; +use pulldown_cmark::{html, Options, Parser}; use tracing::log::*; -use crate::{State, handlers::PageContext}; -use super::{Result, Error}; +use super::{Error, Result}; +use crate::{handlers::PageContext, State}; -pub async fn view( - Path(slug): Path, - Extension(state): Extension>, -) -> Result { +pub async fn view(Path(slug): Path, Extension(state): Extension>) -> Result { let post = state .posts .iter() diff --git a/src/main.rs b/src/main.rs index 5a1c3a3..a9be35b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,11 @@ -use std::{path::PathBuf, sync::Arc}; +use std::sync::Arc; -use axum::{routing::{get, get_service}, Extension, Router, handler::Handler, http::StatusCode}; +use axum::{ + handler::Handler, + http::StatusCode, + routing::{get, get_service}, + Extension, Router, +}; use color_eyre::eyre::Result; use glob::glob; use serde_derive::Serialize; @@ -32,18 +37,18 @@ async fn main() -> Result<()> { .map(|p| { let path = p.unwrap(); - let filename = path - .file_name() - .unwrap() - .to_string_lossy(); + let filename = path.file_name().unwrap().to_string_lossy(); - let (filename, _) = filename.rsplit_once('.') - .unwrap(); + let (filename, _) = filename.rsplit_once('.').unwrap(); let slug = if filename.eq_ignore_ascii_case("index") { - path.parent().unwrap().file_name().unwrap().to_string_lossy().into_owned() - } - else { + path.parent() + .unwrap() + .file_name() + .unwrap() + .to_string_lossy() + .into_owned() + } else { filename.to_owned() }; @@ -64,9 +69,11 @@ async fn main() -> Result<()> { .route("/", get(handlers::index)) .route("/posts/", get(handlers::posts::index)) .route("/posts/:slug/", get(handlers::posts::view)) - .nest("/static", get_service(tower_http::services::ServeDir::new("./static")).handle_error(|e| async { - (StatusCode::NOT_FOUND, "not found") - })) + .nest( + "/static", + get_service(tower_http::services::ServeDir::new("./static")) + .handle_error(|_e| async { (StatusCode::NOT_FOUND, "not found") }), + ) .fallback((|| async { (StatusCode::NOT_FOUND, "not found") }).into_service()) .layer(middleware); @@ -78,7 +85,3 @@ async fn main() -> Result<()> { Ok(()) } - -async fn healthcheck() -> &'static str { - "OK" -}