pub struct Extensions { /* private fields */ }Expand description
A typed map indexed by TypeId. Each T: Any + Send + Sync + 'static
can have at most one value stored.
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 value. Returns the previous value of the same type, if any.
Sourcepub fn get<T: Any + Send + Sync + 'static>(&self) -> Option<&T>
pub fn get<T: Any + Send + Sync + 'static>(&self) -> Option<&T>
Get a reference to a stored value of type T.
Sourcepub fn get_mut<T: Any + Send + Sync + 'static>(&mut self) -> Option<&mut T>
pub fn get_mut<T: Any + Send + Sync + 'static>(&mut self) -> Option<&mut T>
Get a mutable reference to a stored value of type T.
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 the stored value of type T.
Trait Implementations§
Source§impl Clone for Extensions
impl Clone for Extensions
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
Clones the map, but NOT the values inside. Cloning here makes a
fresh empty Extensions — there’s no general way to clone arbitrary
dyn Any. If you need cloned values, store Arc<T> instead of T.
1.0.0 (const: unstable) · 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
Source§impl Serialize for Extensions
impl Serialize for Extensions
Source§fn serialize<Se: Serializer>(&self, s: Se) -> Result<Se::Ok, Se::Error>
fn serialize<Se: Serializer>(&self, s: Se) -> Result<Se::Ok, Se::Error>
Serializes as an empty JSON object. Extensions contains type-erased
runtime data that cannot be generically serialized; the empty-object
representation satisfies S: Serialize bounds without losing any
recoverable information.
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