pub struct IdTypeMap(_);
Expand description

Stores values identified by an Id AND a the std::any::TypeId of the value.

In other words, it maps (Id, TypeId) to any value you want.

Values are cloned when read, so keep them small and light. If you want to store something bigger, wrap them in Arc<Mutex<…>>.

Values can either be “persisted” (serializable) or “temporary” (cleared when egui is shut down).

You can store state using the key Id::null. The state will then only be identified by its type.

let a = Id::new("a");
let b = Id::new("b");
let mut map: IdTypeMap = Default::default();

// `a` associated with an f64 and an i32
map.insert_persisted(a, 3.14);
map.insert_temp(a, 42);

// `b` associated with an f64 and a `&'static str`
map.insert_persisted(b, 13.37);
map.insert_temp(b, "Hello World".to_string());

// we can retrieve all four values:
assert_eq!(map.get_temp::<f64>(a), Some(3.14));
assert_eq!(map.get_temp::<i32>(a), Some(42));
assert_eq!(map.get_temp::<f64>(b), Some(13.37));
assert_eq!(map.get_temp::<String>(b), Some("Hello World".to_string()));

// we can retrieve them like so also:
assert_eq!(map.get_persisted::<f64>(a), Some(3.14));
assert_eq!(map.get_persisted::<i32>(a), Some(42));
assert_eq!(map.get_persisted::<f64>(b), Some(13.37));
assert_eq!(map.get_temp::<String>(b), Some("Hello World".to_string()));

Implementations

Insert a value that will not be persisted.

Insert a value that will be persisted next time you start the app.

Read a value without trying to deserialize a persisted value.

The call clones the value (if found), so make sure it is cheap to clone!

Read a value, optionally deserializing it if available.

The call clones the value (if found), so make sure it is cheap to clone!

Remove the state of this type an id.

Note all state of the given type.

Count how many values are stored but not yet deserialized.

Count the number of values are stored with the given type.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Deserialize this value from the given Serde deserializer. Read more

Serialize this value into the given Serde serializer. 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.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

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.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more