pub struct Before<F>(pub F);Expand description
Define a middleware that operates on incoming requests.
This middleware is useful because it is not possible in Rust yet to use closures to define inline middleware.
§Examples
use tide::{utils, Request};
use std::time::Instant;
let mut app = tide::new();
app.with(utils::Before(|mut request: Request<()>| async move {
request.set_ext(Instant::now());
request
}));Tuple Fields§
§0: FTrait Implementations§
Source§impl<State, F, Fut> Middleware<State> for Before<F>
impl<State, F, Fut> Middleware<State> for Before<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 Before<F>where
F: Freeze,
impl<F> RefUnwindSafe for Before<F>where
F: RefUnwindSafe,
impl<F> Send for Before<F>where
F: Send,
impl<F> Sync for Before<F>where
F: Sync,
impl<F> Unpin for Before<F>where
F: Unpin,
impl<F> UnwindSafe for Before<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