Skip to main content

with_state

Function with_state 

Source
pub fn with_state<S, F, Fut>(state: S, f: F) -> Middleware
where S: Send + Sync + 'static, F: Fn(Arc<S>, Request, Next) -> Fut + Send + Sync + 'static, Fut: Future<Output = Response> + Send + 'static,
Expand description

Middleware with owned state — hides the Arc::clone dance.

Prefer this over capturing many fields and cloning them into each future. If a closure needs more than one .clone(), the state should be one Arc (this helper) or process-lifetime &'static via with_leaked.