pub struct KeyedSlot<Parent, Child, K> {
pub read: for<'a> fn(&'a Parent, &K) -> Option<&'a Child>,
pub write: fn(Option<&Parent>, &K, Child) -> Parent,
}Expand description
Where one of a family of children keeps its record, inside its parent’s.
Slot names a fixed place, which is right when a parent has one child of a kind. A parent
holding a family — one instance per round, per epoch, per slot of a log — needs a place per
member, and the member is not known when the slot is written.
The key is data, not a capture. read and write stay fn pointers and take the key as an
argument, so a keyed slot still names one fixed function; what varies is what it is applied to.
That is what Slot’s own note means by “a slot must not capture”: a slot closing over state
would be a different function on different calls, and this is the same function every time.
The parent is responsible for the keyspace being a keyspace. Two children handed the same key
share a record, exactly as two Slots naming one field would.
Fields§
§read: for<'a> fn(&'a Parent, &K) -> Option<&'a Child>The child’s record for key, as it sits inside the parent’s.
write: fn(Option<&Parent>, &K, Child) -> ParentThe parent’s record with the child’s part for key replaced.