[−][src]Macro photonix::zoom_all
Auto-implements different composites
of getters, setters, and modifiers.
The requirement is that the elements should have an implementation of Get
, GetRef
, Modify
, and Set
with the target type at the next level (see definitions of composites
for details).
Since Get
and GetRef
are traits for structs, this macro is recommended to use with structs.
Examples
#[derive(Get, GetRef, Set, Modify)] pub struct Employee { pub name: String, pub company: Company } #[derive(Get, GetRef, Set, Modify)] pub struct Company { pub name: String, pub address: Address } #[derive(Get, GetRef, Set, Modify)] pub struct Address { pub city: String } let john_doe = Employee { name: String::from("John Doe"), company: Company { name: String::from("Awesome Inc"), address: Address { city: String::from("London"), } } }; // Parent type Level 1 Level 2 // | | | zoom_all![Employee => Company => String]; // Parent type Level 1 Level 2 Level 3 // | | | | zoom_all![Employee => Company => Address => String]; assert_eq!("Awesome Inc", john_doe.get_ref_second().as_str()); assert_eq!("London", john_doe.get_ref_third().as_str()); let john_doe_company_changed_name = john_doe.modify_second(|s| s.replace("Inc", "Corp")); assert_eq!("Awesome Corp", john_doe_company_changed_name.get_ref_second().as_str()); let john_doe_relocated = john_doe_company_changed_name.set_third(String::from("Paris")); assert_eq!("Paris", john_doe_relocated.get_ref_third().as_str());