Skip to main content

Registry

Struct Registry 

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

Source

pub fn new(registry_name: impl Into<Rc<str>>) -> Self

Create a new, empty registry with a given name.

Source

pub fn name(&self) -> &str

Get the name of this registry.

Source

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.

Source

pub fn get(&self, name: &str) -> Option<Rc<T>>

Retrieve an item by name, if it exists.

Source

pub fn remove(&self, name: &str) -> Option<Rc<T>>

Remove an item by name. Returns the removed item if it existed.

Source

pub fn list_names(&self) -> Vec<Rc<str>>

List all registered item names.

Source

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

Check if an item with the given name exists.

Source

pub fn len(&self) -> usize

Get the number of registered items.

Source

pub fn is_empty(&self) -> bool

Check if the registry is empty.

Source

pub fn clear(&self)

Clear all items from the registry.

Source

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.

Source

pub fn list_items(&self) -> Vec<Rc<T>>

Get all registered items as a vector.

Source

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§

Source§

impl<T: Clone> Clone for Registry<T>

Source§

fn clone(&self) -> Registry<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Registry<T>

§

impl<T> !RefUnwindSafe for Registry<T>

§

impl<T> Send for Registry<T>
where T: Sync + Send,

§

impl<T> Sync for Registry<T>
where T: Sync + Send,

§

impl<T> Unpin for Registry<T>

§

impl<T> UnwindSafe for Registry<T>
where T: RefUnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V