pub struct ToolRegistry { /* private fields */ }Expand description
Thread-safe tool registry.
Manages a collection of tools with concurrent access support.
Uses a DashMap for lock-free concurrent operations.
§Features
- Thread-safe registration and lookup
- Tool schema generation for LLM
- Global singleton registry support
§Example
ⓘ
let registry = ToolRegistry::new();
// Register tools
registry.register(ReadFileTool::new())?;
registry.register(WriteFileTool::new())?;
// List all tool schemas
let schemas = registry.list_tools();
// Get and execute a tool
if let Some(tool) = registry.get("read_file") {
let result = tool.execute(json!({"path": "test.txt"})).await?;
}Implementations§
Source§impl ToolRegistry
impl ToolRegistry
Sourcepub fn new() -> ToolRegistry
pub fn new() -> ToolRegistry
Create a new empty tool registry.
Sourcepub fn register<T>(&self, tool: T) -> Result<(), RegistryError>where
T: Tool + 'static,
pub fn register<T>(&self, tool: T) -> Result<(), RegistryError>where
T: Tool + 'static,
Register a tool in the registry.
§Arguments
tool- Tool to register
§Errors
Returns RegistryError::DuplicateTool if tool name already exists.
Returns RegistryError::InvalidTool if tool name is empty.
§Example
ⓘ
registry.register(MyTool::new())?;Sourcepub fn list_tools(&self) -> Vec<ToolSchema>
pub fn list_tools(&self) -> Vec<ToolSchema>
List all tool schemas.
Returns schemas sorted alphabetically by tool name.
Sourcepub fn list_tool_names(&self) -> Vec<String>
pub fn list_tool_names(&self) -> Vec<String>
List all tool names.
Returns names sorted alphabetically.
Sourcepub fn unregister(&self, name: &str) -> bool
pub fn unregister(&self, name: &str) -> bool
Trait Implementations§
Source§impl Default for ToolRegistry
impl Default for ToolRegistry
Source§fn default() -> ToolRegistry
fn default() -> ToolRegistry
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ToolRegistry
impl !RefUnwindSafe for ToolRegistry
impl Send for ToolRegistry
impl Sync for ToolRegistry
impl Unpin for ToolRegistry
impl UnsafeUnpin for ToolRegistry
impl !UnwindSafe for ToolRegistry
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