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 = if seed.exact {
seed.static_key
} else {
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();
if key.explicit_key.is_none() {
assert_eq!(
keys.next_ordinal(key.static_key),
key.ordinal,
"reserved group ordinal must match the active writer state"
);
return;
}
debug_assert_eq!(key.ordinal, 0, "a keyed group has no ordinal");
assert!(
keys.insert_seen(key),
"duplicate sibling group key: {key:?}",
);
}
}