document layer and service
This commit is contained in:
1 parent
d994e3e722
commit
d2f0f4b4b6
2 files changed
+8
-1
No files matched your search
@@ -3,7 +3,9 @@ use tracing_futures::Instrument;
|
|||||||
|
|
||||||
use http::{Request, Response};
|
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 {
|
pub trait Layer: Send + Sync + 'static {
|
||||||
|
/// Wrap a boxed service with this layer
|
||||||
fn layer(&self, inner: BoxedService) -> BoxedService;
|
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 {
|
pub trait Service {
|
||||||
|
/// Run the service and produce a future that resolves to a response
|
||||||
fn run(
|
fn run(
|
||||||
&mut self,
|
&mut self,
|
||||||
req: http::Request<hyper::body::Body>,
|
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>);
|
pub struct BoxedService(pub Box<dyn Service + Send>);
|
||||||
|
|
||||||
impl tower::Service<http::Request<hyper::body::Body>> for BoxedService {
|
impl tower::Service<http::Request<hyper::body::Body>> for BoxedService {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ mod hooks;
|
|||||||
mod hot_reload;
|
mod hot_reload;
|
||||||
pub mod launch;
|
pub mod launch;
|
||||||
#[cfg(feature = "ssr")]
|
#[cfg(feature = "ssr")]
|
||||||
pub mod layer;
|
mod layer;
|
||||||
#[cfg(feature = "ssr")]
|
#[cfg(feature = "ssr")]
|
||||||
mod render;
|
mod render;
|
||||||
#[cfg(feature = "ssr")]
|
#[cfg(feature = "ssr")]
|
||||||
@@ -40,6 +40,8 @@ pub mod prelude {
|
|||||||
#[cfg(not(feature = "ssr"))]
|
#[cfg(not(feature = "ssr"))]
|
||||||
pub use crate::html_storage::deserialize::get_root_props_from_document;
|
pub use crate::html_storage::deserialize::get_root_props_from_document;
|
||||||
pub use crate::launch::LaunchBuilder;
|
pub use crate::launch::LaunchBuilder;
|
||||||
|
#[cfg(feature = "ssr")]
|
||||||
|
pub use crate::layer::{Layer, Service};
|
||||||
#[cfg(all(feature = "ssr", feature = "router"))]
|
#[cfg(all(feature = "ssr", feature = "router"))]
|
||||||
pub use crate::render::pre_cache_static_routes_with_props;
|
pub use crate::render::pre_cache_static_routes_with_props;
|
||||||
#[cfg(feature = "ssr")]
|
#[cfg(feature = "ssr")]
|
||||||
|
|||||||
Reference in new issue
Block a user