Skip to main content

from_fn

Function from_fn 

Source
pub fn from_fn<I, F, Fut>(
    name: &str,
    description: &str,
    handler: F,
) -> AppResult<Box<dyn Callable>>
where I: DeserializeOwned + JsonSchema + Send + 'static, F: Fn(Context, I) -> Fut + Send + Sync + 'static, Fut: Future<Output = AppResult<ToolResult>> + Send + 'static,
Expand description

Create a tool from an async handler function.

Generates JSON Schemas from the input and output type parameters using schemars, and wraps the handler in a type-erased Callable.

The handler receives a Context reference and deserialized input, returning a ToolResult.

§Example

use rskit_tool::from_fn;

let tool = from_fn("search", "Search the web", |_ctx, input: SearchInput| async move {
    Ok(rskit_tool::result::text_result(&format!("found: {}", input.query)))
})?;