pub struct ResourceRegistry { /* private fields */ }Expand description
A registry of resources and resource templates for dynamic dispatch.
Mirrors ToolRegistry for resources: it stores
type-erased RustResource implementations, caches each
ResourceDefinition at registration time, and reads the first resource
whose URI template matches an incoming URI, keeping the type-erasure
machinery a private implementation detail.
Unlike ToolRegistry and
PromptRegistry,
registration is infallible: a ResourceDefinition is built purely from
associated constants and never serializes a JSON schema, so there is no
try_register counterpart.
Implementations§
Source§impl ResourceRegistry
impl ResourceRegistry
Sourcepub fn register<R: RustResource + 'static>(&mut self, resource: R) -> &mut Self
pub fn register<R: RustResource + 'static>(&mut self, resource: R) -> &mut Self
Register a RustResource. Returns &mut Self for chaining.
Sourcepub fn with_resource<R: RustResource + 'static>(self, resource: R) -> Self
pub fn with_resource<R: RustResource + 'static>(self, resource: R) -> Self
Register a RustResource, consuming and returning Self for chaining.
Sourcepub fn definitions(&self) -> Vec<ResourceDefinition>
pub fn definitions(&self) -> Vec<ResourceDefinition>
Collect ResourceDefinitions for all registered resources.
Returns clones of the cached definitions computed at registration time.
Sourcepub fn contains(&self, name: &str) -> bool
pub fn contains(&self, name: &str) -> bool
Whether a resource with the given name is registered.
Note that resources are read by URI (see matches),
not by name; this checks the registered resource name for parity
with ToolRegistry::contains.
Sourcepub fn definition(&self, name: &str) -> Option<&ResourceDefinition>
pub fn definition(&self, name: &str) -> Option<&ResourceDefinition>
Borrow the cached ResourceDefinition for a registered resource by name.
Returns None if no resource named name is registered.
Sourcepub fn iter(&self) -> ResourceDefinitions<'_> ⓘ
pub fn iter(&self) -> ResourceDefinitions<'_> ⓘ
Iterate over (name, definition) pairs for every registered resource.
Yields clones of the cached definitions computed at registration time.
Sourcepub async fn read(&self, uri: &str) -> Result<ResourceOutput, ToolError>
pub async fn read(&self, uri: &str) -> Result<ResourceOutput, ToolError>
Read the first resource whose URI template matches uri.
§Errors
Returns ToolError::not_found if no registered resource’s template
matches uri (carrying error_kind = "not_registered" metadata), or a
read error if URI-variable deserialization or reading fails.
Trait Implementations§
Source§impl Debug for ResourceRegistry
impl Debug for ResourceRegistry
Source§impl Default for ResourceRegistry
impl Default for ResourceRegistry
Source§fn default() -> ResourceRegistry
fn default() -> ResourceRegistry
Source§impl<'a> IntoIterator for &'a ResourceRegistry
Iterate over (name, definition) pairs for every registered resource.
impl<'a> IntoIterator for &'a ResourceRegistry
Iterate over (name, definition) pairs for every registered resource.