pub fn prop<Root, Value>(
keypath: KeyPaths<Root, Value>,
) -> impl Fn(Box<dyn Fn(Value) -> Value>) -> Box<dyn Fn(Root) -> Root>Expand description
Produces an immutable setter function for a given key path. Useful for composing property changes. Equivalent to Swift’s prop<Root, Value>(_ keyPath: WritableKeyPath<Root, Value>) -> (@escaping (Value) -> Value) -> (Root) -> Root
§Examples
use rust_overture::keypaths::prop;
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 update_age = prop(age_keypath);
let double_age = update_age(Box::new(|age| age * 2));
let person = Person { name: "Alice".to_string(), age: 30 };
let updated = double_age(person);
assert_eq!(updated.age, 60);