macro_rules! slot {
($parent:ty, $field:ident) => { ... };
}Expand description
A Slot for an Option field of a Clone + Default parent record — the common case.
slot!(Parent, field) writes the two projections every such slot writes the same way: read the
field, and write the parent with the field replaced, starting from the parent’s default if there
is no parent record yet.
#[derive(Clone, Default, PartialEq, Debug)]
struct Parent { mine: u64, childs: Option<u32> }
const CHILD: Slot<Parent, u32> = slot!(Parent, childs);
assert_eq!((CHILD.write)(None, 7), Parent { mine: 0, childs: Some(7) });
assert_eq!((CHILD.read)(&Parent { mine: 1, childs: Some(3) }), Some(&3));