ExampleMapDynamic

Struct ExampleMapDynamic 

Source
pub struct ExampleMapDynamic {
    pub name: String,
    /* private fields */
}
Expand description

This typemap provides the dynamic section.

Fields§

§name: String

Let’s let the name field be public.

Implementations§

Source§

impl ExampleMapDynamic

Source

pub fn new() -> Self

Construct a new typemap.

All fixed fields will have their specified default value. If there is a dynamic sectionb, it will be empty.

Source

pub fn get_infallible<K: InfallibleKey<ExampleMapDynamic>>(&self) -> &K

Get a value from the typemap which is guaranteed to be present.

Your program won’t compile if it’s not. Compiles down to a simple field borrow.

Source

pub fn get_infallible_mut<K: InfallibleKey<ExampleMapDynamic>>( &mut self, ) -> &mut K

get a mutable reference to a type guaranteed to be in the typemap.

If it’s not, your program won’t compile.

Source

pub fn get<K: Any>(&self) -> Option<&K>

Try to get a type from the typemap.

Source

pub fn get_mut<K: Any>(&mut self) -> Option<&mut K>

Try to get a mutable reference to a value in the typemap.

Source

pub fn insert<K: Any>(&mut self, value: K) -> Result<Option<K>, ()>

Try to insert into the typemap.

Like the std collections, inserting a value that’s already in the map returns Some(old_value) and updates it. Errors if the typemap is fixed and the type provided isn’t present.

Source

pub fn insert_infallible<K: InfallibleKey<Self>>( &mut self, value: K, ) -> Option<K>

Insert into the typemap where the key is known to be in the typemap at the type system level.

Trait Implementations§

Auto Trait Implementations§

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.