pub struct FnLayer<M> { /* private fields */ }
Expand description
A functional layer
This is an example of how to create a layer that adds a header to the response:
let layer = FnLayer::new_closure(move |req, inner| {
async move {
let mut resp = inner.call(req).await;
resp.headers_mut().insert("server", HeaderValue::from_static("potato"));
resp
}
});
Or you can use a struct that implements FnLayerMethod
:
struct MyPlugin;
impl FnLayerMethod for MyPlugin {
async fn call(&self, req: SgRequest, inner: Inner) -> SgResponse {
let mut resp = inner.call(req).await;
resp.headers_mut().insert("server", HeaderValue::from_static("potato"));
resp
}
}
let layer = FnLayer::new(MyPlugin);
Implementations§
Source§impl<H, F, Fut> FnLayer<Handler<H, F, Fut>>where
Handler<H, F, Fut>: FnLayerMethod,
impl<H, F, Fut> FnLayer<Handler<H, F, Fut>>where
Handler<H, F, Fut>: FnLayerMethod,
pub const fn new_handler(h: H) -> Self
Trait Implementations§
Auto Trait Implementations§
impl<M> Freeze for FnLayer<M>where
M: Freeze,
impl<M> RefUnwindSafe for FnLayer<M>where
M: RefUnwindSafe,
impl<M> Send for FnLayer<M>where
M: Send,
impl<M> Sync for FnLayer<M>where
M: Sync,
impl<M> Unpin for FnLayer<M>where
M: Unpin,
impl<M> UnwindSafe for FnLayer<M>where
M: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more