pub struct CtxMapView<'a, S: Schema>(_);
Expand description

Mutable reference to CtxMap where the value has changed.

Use CtxMapViwe instead of &mut CtxMap because &mut CtxMap, whose value has been changed, will be broken if std::mem::swap is used.

Implementations

Sets a value to CtxMap only while f is being called.

Example
ctxmap::schema!(S);
ctxmap::key!(S { KEY_A: u16 = 20 });

let mut m = ctxmap::CtxMap::new();
assert_eq!(m[&KEY_A], 20);
m.with(&KEY_A, &30, |m| {
    assert_eq!(m[&KEY_A], 30);
    m.with(&KEY_A, &40, |m| {
       assert_eq!(m[&KEY_A], 40);
   });
   assert_eq!(m[&KEY_A], 30);
});
assert_eq!(m[&KEY_A], 20);

Return CtxMapView with modified lifetime.

Methods from Deref<Target = CtxMap<S>>

Returns a reference to the value corresponding to the key.

Example
ctxmap::schema!(S);
ctxmap::key!(S { KEY_A: u16 });

let mut m = ctxmap::CtxMap::new();
assert_eq!(m.get(&KEY_A), None);
m.with(&KEY_A, &10, |m| {
    assert_eq!(m.get(&KEY_A), Some(&10));
});
assert_eq!(m.get(&KEY_A), None);

Trait Implementations

The resulting type after dereferencing.

Dereferences the value.

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.