From dc6789bad9d86ece4949d1bb6a01c046b09fe14e Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Sat, 23 Oct 2021 10:38:12 +0800 Subject: [PATCH] add doc example --- src/middleware/boxed.rs | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/middleware/boxed.rs b/src/middleware/boxed.rs index ecf43bfaa..bf7c04a07 100644 --- a/src/middleware/boxed.rs +++ b/src/middleware/boxed.rs @@ -8,6 +8,14 @@ use futures_core::future::LocalBoxFuture; /// Middleware for boxing another middleware's output. It would do type earse for the final middleware service /// and reduce type complexity for potential faster compile time in exchange for extra overhead at runtime. +/// +/// # Examples +/// ``` +/// use actix_web::middleware::{Logger, Boxed}; +/// use actix_web::App; +/// +/// let app = App::new().wrap(Boxed::new(Logger::default())); +/// ``` pub struct Boxed { transform: T, } @@ -29,7 +37,7 @@ where { type Response = T::Response; type Error = T::Error; - type Transform = BoxedMiddleware; + type Transform = BoxService; type InitError = T::InitError; type Future = LocalBoxFuture<'static, Result>; @@ -37,29 +45,11 @@ where let fut = self.transform.new_transform(service); Box::pin(async move { let service = fut.await?; - Ok(BoxedMiddleware { - service: boxed::service(service), - }) + Ok(boxed::service(service)) }) } } -pub struct BoxedMiddleware { - service: BoxService, -} - -impl Service for BoxedMiddleware { - type Response = Res; - type Error = Err; - type Future = LocalBoxFuture<'static, Result>; - - actix_service::forward_ready!(service); - - fn call(&self, req: Req) -> Self::Future { - self.service.call(req) - } -} - #[cfg(test)] mod tests { use super::*;