diff --git a/crates/miniserve/src/lib.rs b/crates/miniserve/src/lib.rs index 7eae083..90d61bf 100644 --- a/crates/miniserve/src/lib.rs +++ b/crates/miniserve/src/lib.rs @@ -1,8 +1,7 @@ #![warn(clippy::pedantic)] -use std::{collections::HashMap, future::Future, io, sync::Arc}; +use std::{collections::HashMap, future::Future, io, pin::Pin, sync::Arc}; use tokio::net::{TcpListener, TcpStream}; -use tokio_util::sync::ReusableBoxFuture; /// Re-export for library clients. pub use http; @@ -40,9 +39,8 @@ where type Future = F; } -struct ErasedHandler( - Box ReusableBoxFuture<'static, Response> + Send + Sync + 'static>, -); +type ErasedHandler = + Box Pin + Send + Sync>> + Send + Sync>; /// The main server data structure. #[derive(Default)] @@ -64,10 +62,10 @@ impl Server { #[must_use] pub fn route(mut self, route: impl Into, handler: H) -> Self { let handler = Arc::new(handler); - let erased = ErasedHandler(Box::new(move |req| { + let erased = Box::new(move |req| { let handler_ref = Arc::clone(&handler); - ReusableBoxFuture::new(async move { handler_ref(req).await }) - })); + Box::pin(handler_ref(req)) as Pin + Send + Sync>> + }); self.routes.insert(route.into(), erased); self } diff --git a/crates/miniserve/src/protocol.rs b/crates/miniserve/src/protocol.rs index 867d78f..74638a9 100644 --- a/crates/miniserve/src/protocol.rs +++ b/crates/miniserve/src/protocol.rs @@ -106,7 +106,7 @@ async fn generate_response<'a>( return make_response(StatusCode::NOT_FOUND, "No valid route"); }; - let response_res = handler.0(request).await; + let response_res = handler(request).await; match response_res { Ok(content) => {