openai_agents_rust/tools/
registry.rs1use crate::tools::traits::Tool;
2use std::sync::Arc;
3
4#[derive(Default)]
5pub struct ToolRegistry {
6 tools: Vec<Arc<dyn Tool>>,
7}
8
9impl ToolRegistry {
10 pub fn new() -> Self {
11 Self { tools: Vec::new() }
12 }
13 pub fn register<T: Tool + 'static>(&mut self, tool: T) {
14 self.tools.push(Arc::new(tool));
15 }
16 pub fn all(&self) -> &[Arc<dyn Tool>] {
17 &self.tools
18 }
19 pub fn get_by_name(&self, name: &str) -> Option<Arc<dyn Tool>> {
20 for t in &self.tools {
21 if t.name() == name {
22 return Some(t.clone());
23 }
24 }
25 None
26 }
27}