pub fn mut_set<Root, Value>(
keypath: KeyPaths<Root, Value>,
value: Value,
) -> impl FnMut(&mut Root)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 rust_overture::keypaths::mut_set;
use key_paths_core::KeyPaths;
#[derive(Clone)]
struct Person {
name: String,
age: u32,
}
let age_keypath = KeyPaths::writable(|person: &mut Person| &mut person.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);