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

Creates an empty 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.

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.

Insert a type into this MetaInfo.

Insert a string k-v into this MetaInfo.

Check if MetaInfo contains entry

Check if MetaInfo contains the given string k-v

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

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

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

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

Clear the MetaInfo of all inserted MetaInfo.

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

Trait Implementations

Formats the value using the given formatter. Read more

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.