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;
use std::sync::Arc;
fn test() {
let mut m1 = MetaInfo::new();
m1.insert::<i8>(2);
assert_eq!(*m1.get::<i8>().unwrap(), 2);
let mut m2 = MetaInfo::from(Arc::new(m1));
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
.
Trait Implementations
sourceimpl Backward for MetaInfo
impl Backward for MetaInfo
fn get_backward_transient<K: AsRef<str>>(&self, key: K) -> Option<&str>
fn get_backward_downstream<K: AsRef<str>>(&self, key: K) -> Option<&str>
fn set_backward_transient<K: Into<Cow<'static, str>>, V: Into<Cow<'static, str>>>(
&mut self,
key: K,
value: V
)
fn set_backward_downstream<K: Into<Cow<'static, str>>, V: Into<Cow<'static, str>>>(
&mut self,
key: K,
value: V
)
fn del_backward_transient<K: AsRef<str>>(&mut self, key: K)
fn del_backward_downstream<K: AsRef<str>>(&mut self, key: K)
fn get_all_backward_transients(
&self
) -> Option<&HashMap<Cow<'static, str>, Cow<'static, str>>>
fn get_all_backward_downstreams(
&self
) -> Option<&HashMap<Cow<'static, str>, Cow<'static, str>>>
fn strip_rpc_prefix_and_set_backward_downstream<K: Into<Cow<'static, str>>, V: Into<Cow<'static, str>>>(
&mut self,
key: K,
value: V
)
fn strip_http_prefix_and_set_backward_downstream<K: Into<Cow<'static, str>>, V: Into<Cow<'static, str>>>(
&mut self,
key: K,
value: V
)
sourceimpl Forward for MetaInfo
impl Forward for MetaInfo
fn get_persistent<K: AsRef<str>>(&self, key: K) -> Option<&str>
fn get_transient<K: AsRef<str>>(&self, key: K) -> Option<&str>
fn get_upstream<K: AsRef<str>>(&self, key: K) -> Option<&str>
fn set_persistent<K: Into<Cow<'static, str>>, V: Into<Cow<'static, str>>>(
&mut self,
key: K,
value: V
)
fn set_transient<K: Into<Cow<'static, str>>, V: Into<Cow<'static, str>>>(
&mut self,
key: K,
value: V
)
fn set_upstream<K: Into<Cow<'static, str>>, V: Into<Cow<'static, str>>>(
&mut self,
key: K,
value: V
)
fn del_persistent<K: AsRef<str>>(&mut self, key: K)
fn del_transient<K: AsRef<str>>(&mut self, key: K)
fn del_upstream<K: AsRef<str>>(&mut self, key: K)
fn get_all_persistents(
&self
) -> Option<&HashMap<Cow<'static, str>, Cow<'static, str>>>
fn get_all_transients(
&self
) -> Option<&HashMap<Cow<'static, str>, Cow<'static, str>>>
fn get_all_upstreams(
&self
) -> Option<&HashMap<Cow<'static, str>, Cow<'static, str>>>
fn strip_rpc_prefix_and_set_persistent<K: Into<Cow<'static, str>>, V: Into<Cow<'static, str>>>(
&mut self,
key: K,
value: V
)
fn strip_rpc_prefix_and_set_upstream<K: Into<Cow<'static, str>>, V: Into<Cow<'static, str>>>(
&mut self,
key: K,
value: V
)
fn strip_http_prefix_and_set_persistent<K: Into<Cow<'static, str>>, V: Into<Cow<'static, str>>>(
&mut self,
key: K,
value: V
)
fn strip_http_prefix_and_set_upstream<K: Into<Cow<'static, str>>, V: Into<Cow<'static, str>>>(
&mut self,
key: K,
value: V
)
Auto Trait Implementations
impl !RefUnwindSafe for MetaInfo
impl Send for MetaInfo
impl Sync for MetaInfo
impl Unpin for MetaInfo
impl !UnwindSafe for MetaInfo
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more