pub struct State<T>(pub T);Expand description
Extract typed application state.
State<T> extracts a value of type T from the router’s application
state. The state is cloned on each request — it must implement
Clone.
The extraction always succeeds (the rejection type is [Infallible])
because the state type is checked at compile time: a handler that asks
for State<Foo> on a router configured with Bar will not compile.
§Example
use volter_core::{State, Handler};
#[derive(Clone)]
struct AppState { counter: u64 }
async fn handler(State(state): State<AppState>) -> String {
format!("counter: {}", state.counter)
}Tuple Fields§
§0: TTrait Implementations§
impl<T: Copy> Copy for State<T>
Source§impl<S: Clone + Send + 'static> FromRequest<S> for State<S>
State also implements FromRequest so it can be the last argument
in a multi-extractor handler tuple. The body is split off and dropped.
impl<S: Clone + Send + 'static> FromRequest<S> for State<S>
State also implements FromRequest so it can be the last argument
in a multi-extractor handler tuple. The body is split off and dropped.
Auto Trait Implementations§
impl<T> Freeze for State<T>where
T: Freeze,
impl<T> RefUnwindSafe for State<T>where
T: RefUnwindSafe,
impl<T> Send for State<T>where
T: Send,
impl<T> Sync for State<T>where
T: Sync,
impl<T> Unpin for State<T>where
T: Unpin,
impl<T> UnsafeUnpin for State<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for State<T>where
T: 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