Struct sfo_http::http_server::utils::After
source · 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>where
State: Clone + Send + Sync + 'static,
F: Fn(Response) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<Response, Error>> + Send + Sync + 'static,
impl<State, F, Fut> Middleware<State> for After<F>where State: Clone + Send + Sync + 'static, F: Fn(Response) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Response, Error>> + Send + Sync + 'static,
source§fn handle<'life0, 'life1, 'async_trait>(
&'life0 self,
request: Request<State>,
next: Next<'life1, State>
) -> Pin<Box<dyn Future<Output = Result<Response, Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
'life1: 'async_trait,
After<F>: 'async_trait,
fn handle<'life0, 'life1, 'async_trait>( &'life0 self, request: Request<State>, next: Next<'life1, State> ) -> Pin<Box<dyn Future<Output = Result<Response, Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, 'life1: 'async_trait, After<F>: 'async_trait,
Asynchronously handle the request, and return a response.
Auto Trait Implementations§
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