pub struct After<F>(pub F);Expand description
Define a middleware that operates on outgoing responses.
This middleware is useful because it is not possible in Rust yet to use closures to define inline middleware.
§Examples
use tide::{utils, http, Response};
let mut app = tide::new();
app.with(utils::After(|res: Response| async move {
match res.status() {
http::StatusCode::NotFound => Ok("Page not found".into()),
http::StatusCode::InternalServerError => Ok("Something went wrong".into()),
_ => Ok(res),
}
}));Tuple Fields§
§0: FTrait Implementations§
Source§impl<State, F, Fut> Middleware<State> for After<F>
impl<State, F, Fut> Middleware<State> for After<F>
Source§fn handle<'life0, 'life1, 'async_trait>(
&'life0 self,
request: Request<State>,
next: Next<'life1, State>,
) -> Pin<Box<dyn Future<Output = Result> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn handle<'life0, 'life1, 'async_trait>(
&'life0 self,
request: Request<State>,
next: Next<'life1, State>,
) -> Pin<Box<dyn Future<Output = Result> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Asynchronously handle the request, and return a response.
Auto Trait Implementations§
impl<F> Freeze for After<F>where
F: Freeze,
impl<F> RefUnwindSafe for After<F>where
F: RefUnwindSafe,
impl<F> Send for After<F>where
F: Send,
impl<F> Sync for After<F>where
F: Sync,
impl<F> Unpin for After<F>where
F: Unpin,
impl<F> UnwindSafe for After<F>where
F: 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