pub struct Next<App = ()> { /* private fields */ }Expand description
A linear, single-use execution cursor over middleware.
Middleware receives ownership of next and may either delegate to the
subsequent middleware in the deque or build a response and terminate
execution altogether.
Next has strict ownership semantics with a consuming API. When the “next”
middleware is called, ownership of self and request are transferred to
the middleware popped from the front of the deque. If the deque is empty,
Next returns a 404 Not Found error.
Because Next owns the remaining middleware chain, choosing not to call it
is how middleware terminates or rejects a request. This makes control flow
explicit: downstream middleware only execute when an upstream middleware
delegates to them.
Next cannot be cloned or reused. This prevents middleware from executing
the same downstream chain more than once, speculatively observing rejected
requests, or continuing execution after a terminal middleware has already
produced a response.
Implementations§
Source§impl<App> Next<App>
impl<App> Next<App>
Sourcepub fn call(self, request: Request<App>) -> BoxFuture
pub fn call(self, request: Request<App>) -> BoxFuture
Call the “next” middleware in the logical call stack for the request.
§Example
use via::{Middleware, middleware};
/// Forwards `request` to the "next" middleware.
fn forward<App>() -> impl Middleware<App> + 'static {
middleware(|request, next| next.call(request))
}