Struct metainfo::MetaInfo

source ·
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§

source§

impl MetaInfo

source

pub fn new() -> MetaInfo

Creates an empty MetaInfo.

source

pub fn from(parent: Arc<MetaInfo>) -> MetaInfo

Creates an MetaInfo with the parent given.

When the info is not found in the current scope, MetaInfo will try to get from parent.

derive is more efficient than this. It is recommended to use derive instead of this.

source

pub fn derive(self) -> (MetaInfo, MetaInfo)

Derives the current MetaInfo, returns two new equivalent Metainfos.

When the info is not found in the current scope, MetaInfo will try to get from parent.

This is the recommended way.

source

pub fn insert<T: Send + Sync + 'static>(&mut self, val: T)

Insert a type into this MetaInfo.

source

pub fn insert_faststr<T: Send + Sync + 'static>(&mut self, val: FastStr)

Insert a faststr newtype into this MetaInfo.

source

pub fn insert_string(&mut self, key: FastStr, val: FastStr)

Insert a string k-v into this MetaInfo.

source

pub fn contains<T: 'static>(&self) -> bool

Check if MetaInfo contains entry

source

pub fn contains_faststr<T: 'static>(&self) -> bool

Check if MetaInfo contains the given Faststr newtype

source

pub fn contains_string<K: AsRef<str>>(&self, key: K) -> bool

Check if MetaInfo contains the given string k-v

source

pub fn get<T: 'static>(&self) -> Option<&T>

Get a reference to a type previously inserted on this MetaInfo.

source

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.

source

pub fn get_faststr<T: 'static>(&self) -> Option<&FastStr>

Get a reference to a faststr newtype previously inserted on this MetaInfo.

source

pub fn remove_faststr<T: 'static>(&mut self) -> Option<FastStr>

Remove a faststr newtype from this MetaInfo and return it. Can only remove the type in the current scope.

source

pub fn get_string<K: AsRef<str>>(&self, key: K) -> Option<&FastStr>

Get a reference to a string k-v previously inserted on this MetaInfo.

source

pub fn remove_string<K: AsRef<str>>(&mut self, key: K) -> Option<FastStr>

Remove a string k-v from this MetaInfo and return it. Can only remove the type in the current scope.

source

pub fn clear(&mut self)

Clear the MetaInfo of all inserted MetaInfo. This will not clear the parent.

source

pub fn extend(&mut self, other: MetaInfo)

Extends self with the items from another MetaInfo. Only extend the items in the current scope.

Trait Implementations§

source§

impl Backward for MetaInfo

source§

impl Debug for MetaInfo

source§

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

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

impl Default for MetaInfo

source§

fn default() -> MetaInfo

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

impl Forward for MetaInfo

source§

fn get_persistent<K: AsRef<str>>(&self, key: K) -> Option<FastStr>

source§

fn get_transient<K: AsRef<str>>(&self, key: K) -> Option<FastStr>

source§

fn get_upstream<K: AsRef<str>>(&self, key: K) -> Option<FastStr>

source§

fn set_persistent<K: Into<FastStr>, V: Into<FastStr>>( &mut self, key: K, value: V )

source§

fn set_transient<K: Into<FastStr>, V: Into<FastStr>>( &mut self, key: K, value: V )

source§

fn set_upstream<K: Into<FastStr>, V: Into<FastStr>>(&mut self, key: K, value: V)

source§

fn del_persistent<K: AsRef<str>>(&mut self, key: K) -> Option<FastStr>

source§

fn del_transient<K: AsRef<str>>(&mut self, key: K) -> Option<FastStr>

source§

fn del_upstream<K: AsRef<str>>(&mut self, key: K) -> Option<FastStr>

source§

fn get_all_persistents(&self) -> Option<&AHashMap<FastStr, FastStr>>

source§

fn get_all_persistents_and_transients_with_rpc_prefix( &self ) -> Option<AHashMap<FastStr, FastStr>>

source§

fn get_all_persistents_and_transients_with_http_prefix( &self ) -> Option<AHashMap<FastStr, FastStr>>

source§

fn get_all_transients(&self) -> Option<&AHashMap<FastStr, FastStr>>

source§

fn get_all_upstreams(&self) -> Option<&AHashMap<FastStr, FastStr>>

source§

fn strip_rpc_prefix_and_set_persistent<K: Into<FastStr>, V: Into<FastStr>>( &mut self, key: K, value: V )

source§

fn strip_rpc_prefix_and_set_upstream<K: Into<FastStr>, V: Into<FastStr>>( &mut self, key: K, value: V )

source§

fn strip_http_prefix_and_set_persistent<K: Into<FastStr>, V: Into<FastStr>>( &mut self, key: K, value: V )

source§

fn strip_http_prefix_and_set_upstream<K: Into<FastStr>, V: Into<FastStr>>( &mut self, key: K, value: V )

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>,

§

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>,

§

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.