use crate::{Key, NodeId, Owned, ScopeId};
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct GroupId(pub(crate) usize);
impl GroupId {
pub(crate) fn new(index: usize) -> Self {
Self(index)
}
pub(crate) fn index(&self) -> usize {
self.0
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct ValueSlotId(pub(crate) usize);
impl ValueSlotId {
pub(crate) fn new(index: usize) -> Self {
Self(index)
}
pub(crate) fn index(&self) -> usize {
self.0
}
}
pub struct StartGroup<G> {
pub group: G,
pub restored_from_gap: bool,
}
pub trait SlotStorage {
type Group: Copy + Eq;
type ValueSlot: Copy + Eq;
fn begin_group(&mut self, key: Key) -> StartGroup<Self::Group>;
fn set_group_scope(&mut self, group: Self::Group, scope: ScopeId);
fn end_group(&mut self);
fn skip_current_group(&mut self);
fn nodes_in_current_group(&self) -> Vec<NodeId>;
fn begin_recranpose_at_scope(&mut self, scope: ScopeId) -> Option<Self::Group>;
fn end_recompose(&mut self);
fn alloc_value_slot<T: 'static>(&mut self, init: impl FnOnce() -> T) -> Self::ValueSlot;
fn read_value<T: 'static>(&self, slot: Self::ValueSlot) -> &T;
fn read_value_mut<T: 'static>(&mut self, slot: Self::ValueSlot) -> &mut T;
fn write_value<T: 'static>(&mut self, slot: Self::ValueSlot, value: T);
fn remember<T: 'static>(&mut self, init: impl FnOnce() -> T) -> Owned<T>;
fn peek_node(&self) -> Option<NodeId>;
fn record_node(&mut self, id: NodeId);
fn advance_after_node_read(&mut self);
fn step_back(&mut self);
fn finalize_current_group(&mut self) -> bool;
fn reset(&mut self);
fn flush(&mut self);
}