pub struct Registry<T> { /* private fields */ }Available on crate feature
azure_policy only.Expand description
Generic thread-safe registry for items of type T using DashMap.
This template can be used to create registries for any type T. It provides thread-safe storage and retrieval operations with customizable registry names.
Implementations§
Source§impl<T> Registry<T>
impl<T> Registry<T>
Sourcepub fn new(registry_name: impl Into<Rc<str>>) -> Self
pub fn new(registry_name: impl Into<Rc<str>>) -> Self
Create a new, empty registry with a given name.
Sourcepub fn register(
&self,
name: impl Into<Rc<str>>,
item: Rc<T>,
) -> Result<(), RegistryError>
pub fn register( &self, name: impl Into<Rc<str>>, item: Rc<T>, ) -> Result<(), RegistryError>
Register an item with a given name. Returns Err if name already exists.
Sourcepub fn remove(&self, name: &str) -> Option<Rc<T>>
pub fn remove(&self, name: &str) -> Option<Rc<T>>
Remove an item by name. Returns the removed item if it existed.
Sourcepub fn list_names(&self) -> Vec<Rc<str>>
pub fn list_names(&self) -> Vec<Rc<str>>
List all registered item names.
Sourcepub fn iter(&self) -> impl Iterator<Item = (Rc<str>, Rc<T>)> + '_
pub fn iter(&self) -> impl Iterator<Item = (Rc<str>, Rc<T>)> + '_
Get an iterator over all entries in the registry. Returns an iterator of (name, item) pairs.
Sourcepub fn list_items(&self) -> Vec<Rc<T>>
pub fn list_items(&self) -> Vec<Rc<T>>
Get all registered items as a vector.
Sourcepub fn try_register(
&self,
name: impl Into<Rc<str>>,
item: Rc<T>,
) -> Result<bool, RegistryError>
pub fn try_register( &self, name: impl Into<Rc<str>>, item: Rc<T>, ) -> Result<bool, RegistryError>
Try to register an item, but don’t fail if the name already exists. Returns Ok(true) if the item was registered, Ok(false) if the name already exists.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Registry<T>
impl<T> !RefUnwindSafe for Registry<T>
impl<T> Send for Registry<T>
impl<T> Sync for Registry<T>
impl<T> Unpin for Registry<T>
impl<T> UnwindSafe for Registry<T>where
T: RefUnwindSafe,
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