pub struct State<T>(pub T);Expand description
Extract shared state.
This extractor clones the state passed to extractor_handler and provides
it to the handler. The state type must match the type passed to the builder.
§Example
use std::sync::Arc;
use tower_mcp::extract::State;
#[derive(Clone)]
struct AppState {
db_url: String,
}
// In an extractor handler:
// |State(state): State<Arc<AppState>>| async move { ... }§Note
For expensive-to-clone types, wrap them in Arc before passing to
extractor_handler.
Tuple Fields§
§0: TTrait Implementations§
Source§impl<S: Clone> FromToolRequest<S> for State<S>
impl<S: Clone> FromToolRequest<S> for State<S>
impl<T: Copy> Copy for State<T>
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> 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