pub struct MetaInfo { /* private fields */ }
Expand description
MetaInfo
is used to passthrough information between components and even client-server.
It supports two types of info: typed map and string k-v.
It is designed to be tree-like, which means you can share a MetaInfo
with multiple children.
Note: only the current scope is mutable.
Examples:
use metainfo::MetaInfo;
fn test() {
let mut m1 = MetaInfo::new();
m1.insert::<i8>(2);
assert_eq!(*m1.get::<i8>().unwrap(), 2);
let (mut m1, mut m2) = m1.derive();
assert_eq!(*m2.get::<i8>().unwrap(), 2);
m2.insert::<i8>(4);
assert_eq!(*m2.get::<i8>().unwrap(), 4);
m2.remove::<i8>();
assert_eq!(*m2.get::<i8>().unwrap(), 2);
}
Implementations
sourceimpl MetaInfo
impl MetaInfo
sourcepub fn derive(self) -> (MetaInfo, MetaInfo)
pub fn derive(self) -> (MetaInfo, MetaInfo)
Derives the current MetaInfo
, returns two new equivalent Metainfo
s.
When the info is not found in the current scope, MetaInfo
will try to get from parent.
This is the recommended way.
sourcepub fn insert_string(&mut self, key: Cow<'static, str>, val: Cow<'static, str>)
pub fn insert_string(&mut self, key: Cow<'static, str>, val: Cow<'static, str>)
Insert a string k-v into this MetaInfo
.
sourcepub fn contains_string(&self, key: &str) -> bool
pub fn contains_string(&self, key: &str) -> bool
Check if MetaInfo
contains the given string k-v
sourcepub fn get<T: 'static>(&self) -> Option<&T>
pub fn get<T: 'static>(&self) -> Option<&T>
Get a reference to a type previously inserted on this MetaInfo
.
sourcepub fn remove<T: 'static>(&mut self) -> Option<T>
pub fn remove<T: 'static>(&mut self) -> Option<T>
Remove a type from this MetaInfo
and return it.
Can only remove the type in the current scope.
sourcepub fn get_string(&self, key: &str) -> Option<&Cow<'static, str>>
pub fn get_string(&self, key: &str) -> Option<&Cow<'static, str>>
Get a reference to a string k-v previously inserted on this MetaInfo
.
sourcepub fn remove_string(&mut self, key: &str) -> Option<Cow<'static, str>>
pub fn remove_string(&mut self, key: &str) -> Option<Cow<'static, str>>
Remove a string k-v from this MetaInfo
and return it.
Can only remove the type in the current scope.