pub struct ToolContext {
pub meta: Meta,
/* private fields */
}Expand description
Tool execution context
Thread-safe context using Arc<DashMap> for extensions.
Can be freely cloned and passed across await points.
§Thread Safety
All operations are thread-safe:
insert,get,removeuse DashMap’s concurrent HashMap- Extensions wrapped in
Arc<T>for cheap cloning
§Examples
use descry_tool_core::ToolContext;
use std::sync::Arc;
let ctx = Arc::new(ToolContext::new());
// Insert extension
#[derive(Debug)]
struct MyService;
ctx.insert(MyService);Fields§
§meta: MetaRequest metadata
Implementations§
Source§impl ToolContext
impl ToolContext
Sourcepub fn with_args(args: JsonObject) -> Self
pub fn with_args(args: JsonObject) -> Self
Create context with args
Sourcepub fn take_args(&mut self) -> Option<JsonObject>
pub fn take_args(&mut self) -> Option<JsonObject>
Take and consume the raw arguments
This can only be called once. Subsequent calls will return None.
Sourcepub fn peek_args(&self) -> Option<&JsonObject>
pub fn peek_args(&self) -> Option<&JsonObject>
Peek at the raw arguments without consuming
Sourcepub fn insert<T>(&self, ext: T) -> Option<Arc<T>>
pub fn insert<T>(&self, ext: T) -> Option<Arc<T>>
Insert an extension into the context
Returns the previous value if it existed.
Trait Implementations§
Source§impl Clone for ToolContext
impl Clone for ToolContext
Source§fn clone(&self) -> ToolContext
fn clone(&self) -> ToolContext
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ToolContext
impl Debug for ToolContext
Auto Trait Implementations§
impl Freeze for ToolContext
impl !RefUnwindSafe for ToolContext
impl Send for ToolContext
impl Sync for ToolContext
impl Unpin for ToolContext
impl UnsafeUnpin for ToolContext
impl !UnwindSafe for ToolContext
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