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
impl ExampleMapDynamic
Sourcepub fn new() -> Self
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.
Sourcepub fn get_infallible<K: InfallibleKey<ExampleMapDynamic>>(&self) -> &K
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.
Sourcepub fn get_infallible_mut<K: InfallibleKey<ExampleMapDynamic>>(
&mut self,
) -> &mut K
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.
Sourcepub fn get_mut<K: Any>(&mut self) -> Option<&mut K>
pub fn get_mut<K: Any>(&mut self) -> Option<&mut K>
Try to get a mutable reference to a value in the typemap.
Sourcepub fn insert<K: Any>(&mut self, value: K) -> Result<Option<K>, ()>
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.
Sourcepub fn insert_infallible<K: InfallibleKey<Self>>(
&mut self,
value: K,
) -> Option<K>
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.