use super::{
super::{GroupKey, GroupKeySeed},
key_state::FrameKeyState,
state::SlotWriteSessionState,
};
impl SlotWriteSessionState {
fn current_keys(&mut self) -> &mut FrameKeyState {
if let Some(frame) = self.group_stack.last_mut() {
&mut frame.keys
} else {
&mut self.root.keys
}
}
fn current_keys_ref(&self) -> &FrameKeyState {
if let Some(frame) = self.group_stack.last() {
&frame.keys
} else {
&self.root.keys
}
}
pub(in crate::slot) fn preview_group_key(&mut self, seed: GroupKeySeed) -> GroupKey {
let static_key = self.mix_branch_fold(seed.static_key);
let ordinal = if seed.explicit_key.is_some() {
0
} else {
self.current_keys_ref().expected_ordinal(static_key)
};
GroupKey::new(static_key, seed.explicit_key, ordinal)
}
pub(in crate::slot) fn consume_group_key(&mut self, key: GroupKey) {
let keys = self.current_keys();
let ordinal = key
.explicit_key
.map_or_else(|| keys.next_ordinal(key.static_key), |_| 0);
debug_assert_eq!(
ordinal, key.ordinal,
"reserved group ordinal must match the active writer state"
);
assert!(
keys.insert_seen(key),
"duplicate sibling group key: {:?}",
key,
);
}
}