pub struct State<T>(pub Arc<T>);Available on non-WebAssembly only.
Expand description
State extractor for #[mcp_tool] functions.
Wraps shared state in Arc<T> and auto-derefs to &T, eliminating
the manual Arc::clone() + move closure ceremony.
§Example
ⓘ
use pmcp::State;
#[mcp_tool(description = "Query database")]
async fn query(args: QueryArgs, db: State<Database>) -> Result<Value> {
db.execute(&args.sql).await // auto-deref to &Database
}
// At registration:
server_builder.tool("query", query().with_state(my_db))Tuple Fields§
§0: Arc<T>Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for State<T>
impl<T> RefUnwindSafe for State<T>where
T: RefUnwindSafe,
impl<T> Send for State<T>
impl<T> Sync for State<T>
impl<T> Unpin for State<T>
impl<T> UnsafeUnpin for State<T>
impl<T> UnwindSafe for State<T>where
T: RefUnwindSafe,
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