pub struct Extensions { /* private fields */ }Expand description
A type-map storing multiple independently-typed extension values.
Each concrete type T: Any + Send + Sync + 'static can be stored at most
once. Values are wrapped in Arc for cheap cloning.
§Example
use zencodec::Extensions;
let mut ext = Extensions::new();
ext.insert(42u32);
ext.insert(99.5f64);
assert_eq!(ext.get::<u32>(), Some(&42));
assert_eq!(ext.get::<f64>(), Some(&99.5));
assert_eq!(ext.get::<i32>(), None);
assert_eq!(ext.len(), 2);Implementations§
Source§impl Extensions
impl Extensions
Sourcepub fn insert<T: Any + Send + Sync + 'static>(&mut self, value: T) -> Option<T>
pub fn insert<T: Any + Send + Sync + 'static>(&mut self, value: T) -> Option<T>
Insert a typed value, replacing any previous value of the same type.
Returns the previous value if one existed and this is the sole Arc
reference, otherwise returns None.
Sourcepub fn get<T: Any + Send + Sync + 'static>(&self) -> Option<&T>
pub fn get<T: Any + Send + Sync + 'static>(&self) -> Option<&T>
Borrow a typed value if present.
Sourcepub fn remove<T: Any + Send + Sync + 'static>(&mut self) -> Option<T>
pub fn remove<T: Any + Send + Sync + 'static>(&mut self) -> Option<T>
Remove and return a typed value.
Returns Some(T) only when this is the sole Arc reference.
Returns None if the type is not present or other references exist.
Trait Implementations§
Source§impl Clone for Extensions
impl Clone for Extensions
Source§fn clone(&self) -> Extensions
fn clone(&self) -> Extensions
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Extensions
impl Debug for Extensions
Source§impl Default for Extensions
impl Default for Extensions
Source§fn default() -> Extensions
fn default() -> Extensions
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for Extensions
impl !RefUnwindSafe for Extensions
impl Send for Extensions
impl Sync for Extensions
impl Unpin for Extensions
impl UnsafeUnpin for Extensions
impl !UnwindSafe for Extensions
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