prop
macro · ferroui-system · v0.5.0
macro_rules! prop
A PropertyPath from getters (x => x.Name, x => x.Address.Street).
use ferroui_system::component_model::INotifyPropertyChanged;
use ferroui_system::events::Event;
use std::cell::Cell;
use std::rc::Rc;
struct Person { age: Cell<i32>, changed: Event<str> }
impl Person {
fn age(&self) -> i32 { self.age.get() }
}
impl INotifyPropertyChanged for Person {
fn property_changed(&self) -> &Event<str> { &self.changed }
}
let path = ferroui_system::prop!(Person => age);
let person = Rc::new(Person { age: Cell::new(3), changed: Event::new() });
assert_eq!(path.get(&person), 3);
assert_eq!(path.path(), "Age");
Each step is a getter method of an object that raises PropertyChanged; its property name is
the getter's in PascalCase (favorite_color is FavoriteColor), or the one given with
as "Name". The steps after the first are objects held in Rc.
prop!(object Type => getter) is the path of one property of an object that does not raise
PropertyChanged itself (PropertyPath::object_property): its step gives the object as its
owner, for an observer chosen at run time.
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.