diff --git a/viz-tower/src/layer.rs b/viz-tower/src/layer.rs new file mode 100644 index 00000000..ab3e826f --- /dev/null +++ b/viz-tower/src/layer.rs @@ -0,0 +1,25 @@ +use viz_core::Transform; + +use crate::Middleware; + +/// Transforms a Tower layer into Viz Middleware. +#[derive(Debug)] +pub struct Layered(L); + +impl Layered { + /// Creates a new tower layer. + pub fn new(l: L) -> Self { + Self(l) + } +} + +impl Transform for Layered +where + L: Clone, +{ + type Output = Middleware; + + fn transform(&self, h: H) -> Self::Output { + Middleware::new(self.0.clone(), h) + } +} diff --git a/viz-tower/src/lib.rs b/viz-tower/src/lib.rs index fb5caef7..535690e8 100644 --- a/viz-tower/src/lib.rs +++ b/viz-tower/src/lib.rs @@ -9,7 +9,10 @@ mod service; pub use service::HandlerService; mod middleware; -pub use middleware::{Layered, Middleware}; +pub use middleware::Middleware; + +mod layer; +pub use layer::Layered; /// Converts a tower [`Service`] into a [`Handler`]. #[derive(Debug, Clone)] diff --git a/viz-tower/src/middleware.rs b/viz-tower/src/middleware.rs index ba2e5d22..45d9f5b0 100644 --- a/viz-tower/src/middleware.rs +++ b/viz-tower/src/middleware.rs @@ -1,33 +1,10 @@ use tower::{Layer, Service, ServiceExt}; use viz_core::{ async_trait, Body, BoxError, Bytes, Error, Handler, HttpBody, Request, Response, Result, - Transform, }; use crate::HandlerService; -/// Transforms a Tower layer into Viz Middleware. -#[derive(Debug)] -pub struct Layered(L); - -impl Layered { - /// Creates a new tower layer. - pub fn new(l: L) -> Self { - Self(l) - } -} - -impl Transform for Layered -where - L: Clone, -{ - type Output = Middleware; - - fn transform(&self, h: H) -> Self::Output { - Middleware::new(self.0.clone(), h) - } -} - /// A [`Service`] created from a [`Handler`] by applying a Tower middleware. #[derive(Debug, Clone)] pub struct Middleware { diff --git a/viz-tower/src/service.rs b/viz-tower/src/service.rs index 96c01830..6247618b 100644 --- a/viz-tower/src/service.rs +++ b/viz-tower/src/service.rs @@ -26,7 +26,7 @@ where impl Service for HandlerService where - H: Handler> + Clone + Send + 'static, + H: Handler> + Send + Clone + 'static, { type Response = Response; type Error = Error;