pub struct ResourceRegistry { /* private fields */ }Expand description
Resource registry for managing handlers and subscriptions
Implementations§
Source§impl ResourceRegistry
impl ResourceRegistry
Sourcepub fn register(
&mut self,
handler: impl ResourceHandler + 'static,
) -> Result<u16, ResourceError>
pub fn register( &mut self, handler: impl ResourceHandler + 'static, ) -> Result<u16, ResourceError>
Register a resource handler
Sourcepub fn handler_count(&self) -> usize
pub fn handler_count(&self) -> usize
Get the number of registered handlers
Sourcepub fn match_uri(&self, uri: &str) -> Option<&dyn ResourceHandler>
pub fn match_uri(&self, uri: &str) -> Option<&dyn ResourceHandler>
Find a handler that matches the given URI
Sourcepub fn handler_id_for_uri(&self, uri: &str) -> Option<u16>
pub fn handler_id_for_uri(&self, uri: &str) -> Option<u16>
Find the registered capability ID for the handler matching the URI.
Sourcepub fn handler_ids(&self) -> Vec<u16>
pub fn handler_ids(&self) -> Vec<u16>
Registered resource capability IDs.
Sourcepub fn allowed_uri_templates<F>(&self, allow_handler: F) -> Vec<String>
pub fn allowed_uri_templates<F>(&self, allow_handler: F) -> Vec<String>
URI templates for registered handlers accepted by a capability predicate.
Sourcepub fn any_allowed_supports_subscribe<F>(&self, allow_handler: F) -> bool
pub fn any_allowed_supports_subscribe<F>(&self, allow_handler: F) -> bool
Whether any accepted handler supports resource subscriptions.
Sourcepub fn list_all(
&self,
cursor: Option<&str>,
) -> Result<ResourceList, ResourceError>
pub fn list_all( &self, cursor: Option<&str>, ) -> Result<ResourceList, ResourceError>
List all resources from all handlers
Sourcepub fn list_allowed<F>(
&self,
cursor: Option<&str>,
allow_handler: F,
) -> Result<ResourceList, ResourceError>
pub fn list_allowed<F>( &self, cursor: Option<&str>, allow_handler: F, ) -> Result<ResourceList, ResourceError>
List resources from handlers accepted by a capability predicate.
Sourcepub fn read(&self, uri: &str) -> Result<ResourceContent, ResourceError>
pub fn read(&self, uri: &str) -> Result<ResourceContent, ResourceError>
Read a resource by URI
Sourcepub fn ensure_subscribable(&self, uri: &str) -> Result<(), ResourceError>
pub fn ensure_subscribable(&self, uri: &str) -> Result<(), ResourceError>
Validate that a concrete resource URI is eligible for subscriptions.
Sourcepub async fn subscribe<F>(
&self,
uri: &str,
callback: F,
) -> Result<SubscriptionId, ResourceError>
pub async fn subscribe<F>( &self, uri: &str, callback: F, ) -> Result<SubscriptionId, ResourceError>
Subscribe to resource changes
Sourcepub async fn unsubscribe(&self, id: SubscriptionId) -> bool
pub async fn unsubscribe(&self, id: SubscriptionId) -> bool
Unsubscribe from resource changes
Sourcepub async fn notify_change(&self, uri: &str)
pub async fn notify_change(&self, uri: &str)
Notify all subscribers of a resource change
Sourcepub async fn subscription_count(&self, uri: &str) -> usize
pub async fn subscription_count(&self, uri: &str) -> usize
Get subscription count for a URI
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ResourceRegistry
impl !RefUnwindSafe for ResourceRegistry
impl !UnwindSafe for ResourceRegistry
impl Send for ResourceRegistry
impl Sync for ResourceRegistry
impl Unpin for ResourceRegistry
impl UnsafeUnpin for ResourceRegistry
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