mprop_ref

Function mprop_ref 

Source
pub fn mprop_ref<Root, Value>(
    keypath: KeyPaths<Root, Value>,
) -> impl Fn(Box<dyn Fn(Value)>) -> Box<dyn Fn(Root)>
where Root: Clone + 'static, Value: Clone + 'static,
Expand description

Produces a reference-mutable setter function for a given key path to a reference. Useful for composing reference property changes efficiently. Equivalent to Swift’s mprop<Root, Value>(_ keyPath: ReferenceWritableKeyPath<Root, Value>) -> (@escaping (Value) -> Void) -> (Root) -> Void where Value: AnyObject

§Examples

use rust_overture::keypaths::mprop_ref;
use key_paths_core::KeyPaths;

#[derive(Clone)]
struct Person {
    name: String,
    age: u32,
}

let name_keypath = KeyPaths::writable(|person: &mut Person| &mut person.name);
let mut_update_name = mprop_ref(name_keypath);
let mut uppercase_name = mut_update_name(Box::new(|mut name| name.make_ascii_uppercase()));
let person = Person { name: "alice".to_string(), age: 30 };
uppercase_name(person);