mut_set

Function mut_set 

Source
pub fn mut_set<Root, Value>(
    keypath: WritableKeyPath<Root, Value>,
    value: Value,
) -> impl FnMut(&mut Root)
where Root: 'static, Value: Clone + 'static,
Expand description

Produces a value-mutable setter function for a given key path and new value. Equivalent to Swift’s mut<Root, Value>(_ keyPath: WritableKeyPath<Root, Value>, _ value: Value) -> (inout Root) -> Void

§Examples

use overture_core::keypath::{WritableKeyPath, mut_set};

let age_keypath = WritableKeyPath::new(
    |person: &Person| person.age,
    |person: &mut Person, age| person.age = age
);
let mut set_age_25 = mut_set(age_keypath, 25);
let mut person = Person { name: "Alice".to_string(), age: 30 };
set_age_25(&mut person);
assert_eq!(person.age, 25);