Struct TypeMap

Source
pub struct TypeMap<A = dyn UnsafeAny>
where A: UnsafeAnyExt + ?Sized,
{ /* private fields */ }

Implementations§

Source§

impl TypeMap

Source

pub fn new() -> TypeMap

Create a new, empty TypeMap.

Source§

impl<A: UnsafeAnyExt + ?Sized> TypeMap<A>

Source

pub fn custom() -> TypeMap<A>

Create a new, empty TypeMap.

Can be used with any A parameter; new is specialized to get around the required type annotations when using this function.

Source

pub fn put<K: Key>(&mut self, val: K::Value) -> Option<K::Value>
where K::Value: Any + Implements<A>,

Insert a value into the map with a specified key type.

Source

pub fn get<K: Key>(&self) -> &K::Value
where K::Value: Any + Implements<A>,

Gets a value from the type map.

§Panics

If there is no value in the request state of the given type.

Source

pub fn try_get<K: Key>(&self) -> Option<&K::Value>
where K::Value: Any + Implements<A>,

Attempt to get a value from the type map.

Source

pub fn has<K: Key>(&self) -> bool

Check if a key has an associated value stored in the map.

Trait Implementations§

Source§

impl<A> Debug for TypeMap<A>
where A: UnsafeAnyExt + Debug + ?Sized,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<A> Default for TypeMap<A>
where A: UnsafeAnyExt + Default + ?Sized,

Source§

fn default() -> TypeMap<A>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<A> Freeze for TypeMap<A>
where A: ?Sized,

§

impl<A> RefUnwindSafe for TypeMap<A>
where A: RefUnwindSafe + ?Sized,

§

impl<A> Send for TypeMap<A>
where A: Send + ?Sized,

§

impl<A> Sync for TypeMap<A>
where A: Sync + ?Sized,

§

impl<A> Unpin for TypeMap<A>
where A: ?Sized,

§

impl<A> UnwindSafe for TypeMap<A>
where A: UnwindSafe + ?Sized,

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> 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, 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<T> UnsafeAny for T
where T: Any,