Removed tokio feature and added tokio to axum feature

This commit is contained in:
Martin Berg Alstad 2024-06-30 23:39:00 +02:00
parent 0898a50166
commit 963c0610e5
4 changed files with 9 additions and 14 deletions

2
Cargo.lock generated
View File

@ -294,7 +294,7 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "lib"
version = "1.3.0"
version = "1.3.1"
dependencies = [
"axum",
"derive",

View File

@ -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"]

View File

@ -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<TcpListener> {
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;

View File

@ -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<Path>(file_path: Path) -> Result<Html<Body>, io::Error>
where
Path: AsRef<std::path::Path>,
@ -18,7 +18,7 @@ where
load_file(file_path).await.map(Html)
}
#[cfg(feature = "tokio")]
#[cfg(feature = "io")]
pub async fn load_file<Path>(file_path: Path) -> Result<Body, io::Error>
where
Path: AsRef<std::path::Path>,
@ -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::*;