diff --git a/http/src/h1/body.rs b/http/src/h1/body.rs index cd4016a3..f0e5585c 100644 --- a/http/src/h1/body.rs +++ b/http/src/h1/body.rs @@ -1,6 +1,6 @@ use core::{ cell::{RefCell, RefMut}, - future::{Future, poll_fn}, + future::poll_fn, ops::DerefMut, pin::Pin, task::{Context, Poll, Waker}, diff --git a/http/src/h1/dispatcher.rs b/http/src/h1/dispatcher.rs index da47bd45..b477b100 100644 --- a/http/src/h1/dispatcher.rs +++ b/http/src/h1/dispatcher.rs @@ -1,6 +1,6 @@ use core::{ convert::Infallible, - future::{Future, pending, poll_fn}, + future::{pending, poll_fn}, marker::PhantomData, net::SocketAddr, pin::{Pin, pin}, diff --git a/http/src/h1/dispatcher_uring.rs b/http/src/h1/dispatcher_uring.rs index 2825da9e..7a305679 100644 --- a/http/src/h1/dispatcher_uring.rs +++ b/http/src/h1/dispatcher_uring.rs @@ -1,7 +1,7 @@ use core::{ cell::RefCell, fmt, - future::{Future, poll_fn}, + future::poll_fn, marker::PhantomData, mem, net::SocketAddr, diff --git a/http/src/tls/native_tls.rs b/http/src/tls/native_tls.rs index 056253da..177dc74d 100644 --- a/http/src/tls/native_tls.rs +++ b/http/src/tls/native_tls.rs @@ -3,7 +3,6 @@ pub(crate) use native_tls::TlsAcceptor; use core::{ convert::Infallible, fmt, - future::Future, pin::Pin, task::{Context, Poll}, }; diff --git a/http/src/util/futures.rs b/http/src/util/futures.rs index 5bfe864c..1f87b713 100644 --- a/http/src/util/futures.rs +++ b/http/src/util/futures.rs @@ -3,8 +3,6 @@ pub(crate) use queue::*; #[cfg(any(feature = "http2", feature = "http3"))] mod queue { - use core::future::Future; - use futures_util::stream::{FuturesUnordered, StreamExt}; pub(crate) struct Queue(FuturesUnordered); diff --git a/http/src/util/middleware/context.rs b/http/src/util/middleware/context.rs index 0a160a4e..68806599 100644 --- a/http/src/util/middleware/context.rs +++ b/http/src/util/middleware/context.rs @@ -1,6 +1,6 @@ //! middleware for adding typed state to service request. -use core::{fmt, future::Future}; +use core::fmt; use xitca_service::Service; diff --git a/http/src/util/service/handler.rs b/http/src/util/service/handler.rs index 9d937290..38c3a837 100644 --- a/http/src/util/service/handler.rs +++ b/http/src/util/service/handler.rs @@ -2,7 +2,7 @@ #![allow(non_snake_case)] -use core::{convert::Infallible, future::Future, marker::PhantomData, net::SocketAddr}; +use core::{convert::Infallible, marker::PhantomData, net::SocketAddr}; use xitca_service::{Service, pipeline::PipelineE}; diff --git a/http/src/util/service/router.rs b/http/src/util/service/router.rs index 394154d9..cff6b081 100644 --- a/http/src/util/service/router.rs +++ b/http/src/util/service/router.rs @@ -21,7 +21,7 @@ pub use self::object::RouteObject; /// in order to determine how the router type-erases node services. pub struct Router { // record for last time PathGen is called with certain route string prefix. - prefix: Option, + prefix: usize, routes: HashMap, } @@ -34,7 +34,7 @@ impl Default for Router { impl Router { pub fn new() -> Self { Router { - prefix: None, + prefix: 0, routes: HashMap::new(), } } @@ -183,8 +183,7 @@ where path.pop(); } - let prefix = self.prefix.get_or_insert(0); - *prefix += path.len(); + self.prefix += path.len(); self.routes.iter_mut().for_each(|(_, v)| { v.path_gen(path.as_str()); @@ -436,7 +435,7 @@ mod service { pub struct RouterService { // a length record of prefix of current router. // when it's Some the request path has to be sliced to exclude the string path prefix. - pub(super) prefix: Option, + pub(super) prefix: usize, pub(super) router: xitca_router::Router, } @@ -452,15 +451,11 @@ mod service { // using async fn call directly would cause significant code bloating. #[allow(clippy::manual_async_fn)] #[inline] - fn call(&self, mut req: Req) -> impl core::future::Future> { + fn call(&self, mut req: Req) -> impl Future> { async { - let mut path = req.borrow().path(); - - if let Some(prefix) = self.prefix { - path = &path[prefix..]; - } - - let xitca_router::Match { value, params } = self.router.at(path).map_err(RouterError::Match)?; + let path = req.borrow().path(); + let xitca_router::Match { value, params } = + self.router.at(&path[self.prefix..]).map_err(RouterError::Match)?; *req.borrow_mut() = params; Service::call(value, req).await } diff --git a/http/src/util/timer.rs b/http/src/util/timer.rs index b9af89af..1153f5cb 100644 --- a/http/src/util/timer.rs +++ b/http/src/util/timer.rs @@ -1,5 +1,4 @@ -use std::{ - future::Future, +use core::{ pin::Pin, task::{Context, Poll, ready}, };