pub fn mver<Root, Value>(
keypath: KeyPaths<Root, Value>,
update: impl FnMut(&mut Value) + 'static,
) -> impl FnMut(&mut Root)Expand description
Uncurried mver. Takes a key path and update function all at once.
Equivalent to Swift’s mver<Root, Value>(_ keyPath: WritableKeyPath<Root, Value>, _ update: @escaping (inout Value) -> Void) -> (inout Root) -> Void
§Examples
use rust_overture::keypaths::mver;
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 double_age = mver(age_keypath, |age| *age *= 2);
let mut person = Person { name: "Alice".to_string(), age: 30 };
double_age(&mut person);
assert_eq!(person.age, 60);