pub struct TypedTool<H>(pub H);Expand description
Wraps a typed ToolHandler as a type-erased DynTool.
This adapter is where erasure happens for native Rust tools:
call_json deserializes the incoming Value into the
handler’s Input, calls the typed handler, and serializes its Output back
to a Value. A Suspension passes through untouched.
A newtype wrapper is used rather than a blanket impl<H: ToolHandler> DynTool for H, so that MCP-backed tools remain free to implement DynTool
directly for their own types without a coherence conflict.
ToolSet::register wraps handlers in this
automatically, so most callers never name it.
Tuple Fields§
§0: HImplementations§
Trait Implementations§
Source§impl<H: ToolHandler> DynTool for TypedTool<H>
impl<H: ToolHandler> DynTool for TypedTool<H>
Source§fn description(&self) -> &str
fn description(&self) -> &str
The human-readable description handed to the model.
Source§fn input_schema(&self) -> Value
fn input_schema(&self) -> Value
The JSON Schema the tool’s input must satisfy.
Source§fn call_json<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 ToolCtx,
input: Value,
) -> Pin<Box<dyn Future<Output = Result<ToolOutcome<Value>, ToolError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn call_json<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 ToolCtx,
input: Value,
) -> Pin<Box<dyn Future<Output = Result<ToolOutcome<Value>, ToolError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Dispatches the tool with JSON input, returning JSON output or a
suspension. Read more
Source§fn descriptor(&self) -> ToolDescriptor
fn descriptor(&self) -> ToolDescriptor
A cloneable metadata snapshot for handing to a model. Provided; built
from the four accessors above.
Auto Trait Implementations§
impl<H> Freeze for TypedTool<H>where
H: Freeze,
impl<H> RefUnwindSafe for TypedTool<H>where
H: RefUnwindSafe,
impl<H> Send for TypedTool<H>where
H: Send,
impl<H> Sync for TypedTool<H>where
H: Sync,
impl<H> Unpin for TypedTool<H>where
H: Unpin,
impl<H> UnsafeUnpin for TypedTool<H>where
H: UnsafeUnpin,
impl<H> UnwindSafe for TypedTool<H>where
H: 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