|
@@ -3,7 +3,9 @@ use tracing_futures::Instrument;
|
|
|
|
|
|
use http::{Request, Response};
|
|
|
|
|
|
+/// A layer that wraps a service. This can be used to add additional information to the request, or response on top of some other service
|
|
|
pub trait Layer: Send + Sync + 'static {
|
|
|
+ /// Wrap a boxed service with this layer
|
|
|
fn layer(&self, inner: BoxedService) -> BoxedService;
|
|
|
}
|
|
|
|
|
@@ -17,7 +19,9 @@ where
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/// A service is a function that takes a request and returns an async response
|
|
|
pub trait Service {
|
|
|
+ /// Run the service and produce a future that resolves to a response
|
|
|
fn run(
|
|
|
&mut self,
|
|
|
req: http::Request<hyper::body::Body>,
|
|
@@ -55,6 +59,7 @@ where
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/// A boxed service is a type-erased service that can be used without knowing the underlying type
|
|
|
pub struct BoxedService(pub Box<dyn Service + Send>);
|
|
|
|
|
|
impl tower::Service<http::Request<hyper::body::Body>> for BoxedService {
|