pub struct ExtensionPoint<T: ?Sized> { /* private fields */ }Expand description
Typed, name-indexed collection of Arc<T>.
Cheap to clone; clones share the same underlying entries.
Implementations§
Source§impl<T: ?Sized> ExtensionPoint<T>
impl<T: ?Sized> ExtensionPoint<T>
Source§impl<T: ?Sized + Send + Sync + 'static> ExtensionPoint<T>
impl<T: ?Sized + Send + Sync + 'static> ExtensionPoint<T>
Sourcepub fn register(
&self,
name: impl Into<String>,
value: Arc<T>,
) -> Result<(), ExtensionError>
pub fn register( &self, name: impl Into<String>, value: Arc<T>, ) -> Result<(), ExtensionError>
Register a new entry. Errors if the name is already in use.
§Errors
ExtensionError::AlreadyRegisteredif the name is taken.ExtensionError::LockPoisonedif the internal lock was poisoned by a panic.
Sourcepub fn register_or_replace(
&self,
name: impl Into<String>,
value: Arc<T>,
) -> Option<Arc<T>>
pub fn register_or_replace( &self, name: impl Into<String>, value: Arc<T>, ) -> Option<Arc<T>>
Register a new entry, replacing any existing one with the same
name. Returns the previous Arc<T>, or None if there was none.
Sourcepub fn unregister(&self, name: &str) -> Result<Option<Arc<T>>, ExtensionError>
pub fn unregister(&self, name: &str) -> Result<Option<Arc<T>>, ExtensionError>
Remove an entry. Returns the removed Arc<T>, or None if the
name was not present.
Refuses to remove an entry whose strong count is greater than one (i.e. external callers still hold a reference).
Sourcepub fn replace(&self, name: &str, new: Arc<T>) -> Result<Arc<T>, ExtensionError>
pub fn replace(&self, name: &str, new: Arc<T>) -> Result<Arc<T>, ExtensionError>
Atomically replace an entry. Returns the previous Arc<T>, or
ExtensionError::NotFound if the name was not present.
After this call, new ExtensionPoint::get calls return new.
Callers that already hold the old Arc<T> continue to operate on
the old instance until they drop it.
§Errors
ExtensionError::NotFoundif the name was not present.
Sourcepub fn get_required(&self, name: &str) -> Result<Arc<T>, ExtensionError>
pub fn get_required(&self, name: &str) -> Result<Arc<T>, ExtensionError>
Look up an entry by name, returning ExtensionError::NotFound
if missing.