Skip to main content

GroupedRegistry

Struct GroupedRegistry 

Source
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" tools

Implementations§

Source§

impl GroupedRegistry

Source

pub fn new() -> GroupedRegistry

Create an empty grouped registry.

Source

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.

Source

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.

Source

pub fn activate_group(&self, name: &str) -> bool

Activate a group at runtime (non-builder).

Returns true if the group exists and was activated.

Source

pub fn deactivate_group(&self, name: &str) -> bool

Deactivate a group at runtime.

Returns true if the group was previously active.

Source

pub fn group_names(&self) -> Vec<String>

Get the names of all registered groups.

Source

pub fn active_group_names(&self) -> Vec<String>

Get the names of currently active groups.

Source

pub fn is_group_active(&self, name: &str) -> bool

Check if a specific group is currently active.

Trait Implementations§

Source§

impl Default for GroupedRegistry

Source§

fn default() -> GroupedRegistry

Returns the “default value” for a type. Read more
Source§

impl ToolRegistry for GroupedRegistry

Source§

fn get_tools(&self) -> Vec<Arc<dyn ErasedTool>>

Returns tools from active groups only.

Source§

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 len(&self) -> usize

Returns the number of tools in active groups only.

Source§

fn is_empty(&self) -> bool

Check if the registry has no enabled tools.
Source§

fn register(&self, _tool: Arc<dyn ErasedTool>) -> bool

Register a new tool. Returns true if the tool was added. Read more
Source§

fn unregister(&self, _name: &str) -> bool

Unregister a tool by name. Returns true if the tool was removed. Read more
Source§

fn set_enabled(&self, _name: &str, _enabled: bool) -> bool

Enable or disable a tool by name. Returns true if the state changed. Read more
Source§

fn is_enabled(&self, name: &str) -> bool

Check if a tool is currently enabled.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more