diff --git a/Cargo.lock b/Cargo.lock index 78f9692..a7ce814 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -294,7 +294,7 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "lib" -version = "1.3.0" +version = "1.3.1" dependencies = [ "axum", "derive", diff --git a/Cargo.toml b/Cargo.toml index 47be2b5..b71a070 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lib" -version = "1.3.0" +version = "1.3.1" edition = "2021" authors = ["Martin Berg Alstad"] @@ -27,8 +27,7 @@ serde = { version = "1.0.203", optional = true, features = ["derive"] } derive = { path = "derive", optional = true } [features] -axum = ["dep:axum", "dep:tower", "dep:tower-http", "dep:thiserror", "dep:tracing", "dep:tracing-subscriber"] -tokio = ["dep:tokio"] +axum = ["dep:axum", "dep:tower", "dep:tower-http", "dep:thiserror", "dep:tracing", "dep:tracing-subscriber", "dep:tokio"] io = ["dep:tokio", "dep:tokio-util"] iter = [] nom = ["dep:nom"] diff --git a/src/axum/app.rs b/src/axum/app.rs index 806d96e..dbe2a63 100644 --- a/src/axum/app.rs +++ b/src/axum/app.rs @@ -1,6 +1,7 @@ use { axum::{extract::Request, handler::Handler, Router, ServiceExt}, - std::net::Ipv4Addr, + std::{io, net::Ipv4Addr, net::SocketAddr}, + tokio::net::TcpListener, tower::layer::Layer, tower_http::{ cors::CorsLayer, @@ -10,8 +11,6 @@ use { }, tracing::{info, Level}, }; -#[cfg(feature = "tokio")] -use {std::io, std::net::SocketAddr, tokio::net::TcpListener}; // TODO trim trailing slash into macro > let _app = NormalizePathLayer::trim_trailing_slash().layer(create_app!(routes)); #[macro_export] @@ -77,7 +76,6 @@ impl AppBuilder { self } - #[cfg(feature = "tokio")] pub async fn serve(self) -> io::Result<()> { let _ = fmt_trace(); // Allowed to fail let listener = self.listener().await?; @@ -92,7 +90,6 @@ impl AppBuilder { Ok(()) } - #[cfg(feature = "tokio")] async fn listener(&self) -> io::Result { let addr = SocketAddr::from(self.socket.unwrap_or((Ipv4Addr::UNSPECIFIED, 8000))); info!("Initializing server on: {addr}"); @@ -128,7 +125,6 @@ mod tests { use super::*; - #[cfg(feature = "tokio")] mod tokio_tests { use std::time::Duration; diff --git a/src/axum/load.rs b/src/axum/load.rs index e4cd8d9..19f74dc 100644 --- a/src/axum/load.rs +++ b/src/axum/load.rs @@ -1,4 +1,4 @@ -#[cfg(feature = "tokio")] +#[cfg(feature = "io")] use {crate::io::file, axum::body::Body, axum::response::Html, std::io}; /// Load an HTML file from the given file path, relative to the current directory. @@ -10,7 +10,7 @@ use {crate::io::file, axum::body::Body, axum::response::Html, std::io}; /// ``` /// let html = async { lib::axum::load::load_html("openapi.html").await.unwrap() }; /// ``` -#[cfg(feature = "tokio")] +#[cfg(feature = "io")] pub async fn load_html(file_path: Path) -> Result, io::Error> where Path: AsRef, @@ -18,7 +18,7 @@ where load_file(file_path).await.map(Html) } -#[cfg(feature = "tokio")] +#[cfg(feature = "io")] pub async fn load_file(file_path: Path) -> Result where Path: AsRef, @@ -70,7 +70,7 @@ mod tests { load_html!("load.rs", "{{replace_me}}" => "hello", "{{replace_me_too}}" => "world"); } - #[cfg(feature = "tokio")] + #[cfg(feature = "io")] mod tokio { use super::super::*;