pub struct GroupedRegistry { /* private fields */ }Expand description
A tool registry that organizes tools into named groups with group-level activation and deactivation.
Only tools in active groups are returned by get_tools(), while
find_tool() searches all groups (active or not) to ensure tool
execution is always possible even for deactivated groups.
Uses RwLock for interior mutability — group switching is safe from &self.
§Example
use traitclaw_core::registries::GroupedRegistry;
use traitclaw_core::traits::tool_registry::ToolRegistry;
let registry = GroupedRegistry::new();
assert!(registry.is_empty());use traitclaw_core::registries::GroupedRegistry;
use traitclaw_core::traits::tool_registry::ToolRegistry;
let registry = GroupedRegistry::new()
// .group("search", vec![web_search, deep_search])
// .group("code", vec![read_file, write_file])
.activate("search");
// Only "search" tools are returned by get_tools()
// But find_tool() can still find "code" toolsImplementations§
Source§impl GroupedRegistry
impl GroupedRegistry
Sourcepub fn new() -> GroupedRegistry
pub fn new() -> GroupedRegistry
Create an empty grouped registry.
Sourcepub fn group(
self,
name: impl Into<String>,
tools: Vec<Arc<dyn ErasedTool>>,
) -> GroupedRegistry
pub fn group( self, name: impl Into<String>, tools: Vec<Arc<dyn ErasedTool>>, ) -> GroupedRegistry
Add a named group of tools.
Tools are provided as Arc<dyn ErasedTool>. The group is not
activated automatically — call activate() to enable it.
If a group with the same name already exists, it is replaced.
Sourcepub fn activate(self, name: impl Into<String>) -> GroupedRegistry
pub fn activate(self, name: impl Into<String>) -> GroupedRegistry
Activate a group, making its tools visible via get_tools().
Multiple groups can be active simultaneously. Activating an already-active group is a no-op.
Sourcepub fn activate_group(&self, name: &str) -> bool
pub fn activate_group(&self, name: &str) -> bool
Activate a group at runtime (non-builder).
Returns true if the group exists and was activated.
Sourcepub fn deactivate_group(&self, name: &str) -> bool
pub fn deactivate_group(&self, name: &str) -> bool
Deactivate a group at runtime.
Returns true if the group was previously active.
Sourcepub fn group_names(&self) -> Vec<String>
pub fn group_names(&self) -> Vec<String>
Get the names of all registered groups.
Sourcepub fn active_group_names(&self) -> Vec<String>
pub fn active_group_names(&self) -> Vec<String>
Get the names of currently active groups.
Sourcepub fn is_group_active(&self, name: &str) -> bool
pub fn is_group_active(&self, name: &str) -> bool
Check if a specific group is currently active.
Trait Implementations§
Source§impl Default for GroupedRegistry
impl Default for GroupedRegistry
Source§fn default() -> GroupedRegistry
fn default() -> GroupedRegistry
Source§impl ToolRegistry for GroupedRegistry
impl ToolRegistry for GroupedRegistry
Source§fn find_tool(&self, name: &str) -> Option<Arc<dyn ErasedTool>>
fn find_tool(&self, name: &str) -> Option<Arc<dyn ErasedTool>>
Searches all groups (active or not) for a tool by name.
This allows tool execution even when the tool’s group is deactivated.
Source§fn register(&self, _tool: Arc<dyn ErasedTool>) -> bool
fn register(&self, _tool: Arc<dyn ErasedTool>) -> bool
true if the tool was added. Read moreSource§fn unregister(&self, _name: &str) -> bool
fn unregister(&self, _name: &str) -> bool
true if the tool was removed. Read moreSource§fn set_enabled(&self, _name: &str, _enabled: bool) -> bool
fn set_enabled(&self, _name: &str, _enabled: bool) -> bool
true if the state changed. Read more