cranpose_core/
hierarchical_slot_storage.rs1use crate::{
8 slot_storage::{GroupId, SlotStorage, StartGroup, ValueSlotId},
9 Key, NodeId, Owned, ScopeId, SlotTable,
10};
11
12#[derive(Default)]
17pub struct HierarchicalSlotStorage {
18 root: SlotTable,
20}
21
22impl HierarchicalSlotStorage {
23 pub fn new() -> Self {
24 Self {
25 root: SlotTable::new(),
26 }
27 }
28}
29
30impl SlotStorage for HierarchicalSlotStorage {
31 type Group = GroupId;
32 type ValueSlot = ValueSlotId;
33
34 fn begin_group(&mut self, key: Key) -> StartGroup<Self::Group> {
35 SlotStorage::begin_group(&mut self.root, key)
36 }
37
38 fn set_group_scope(&mut self, group: Self::Group, scope: ScopeId) {
39 SlotStorage::set_group_scope(&mut self.root, group, scope);
40 }
41
42 fn end_group(&mut self) {
43 SlotStorage::end_group(&mut self.root);
44 }
45
46 fn skip_current_group(&mut self) {
47 SlotStorage::skip_current_group(&mut self.root);
48 }
49
50 fn nodes_in_current_group(&self) -> Vec<NodeId> {
51 SlotStorage::nodes_in_current_group(&self.root)
52 }
53
54 fn begin_recranpose_at_scope(&mut self, scope: ScopeId) -> Option<Self::Group> {
55 SlotStorage::begin_recranpose_at_scope(&mut self.root, scope)
56 }
57
58 fn end_recompose(&mut self) {
59 SlotStorage::end_recompose(&mut self.root);
60 }
61
62 fn alloc_value_slot<T: 'static>(&mut self, init: impl FnOnce() -> T) -> Self::ValueSlot {
63 SlotStorage::alloc_value_slot(&mut self.root, init)
64 }
65
66 fn read_value<T: 'static>(&self, slot: Self::ValueSlot) -> &T {
67 SlotStorage::read_value(&self.root, slot)
68 }
69
70 fn read_value_mut<T: 'static>(&mut self, slot: Self::ValueSlot) -> &mut T {
71 SlotStorage::read_value_mut(&mut self.root, slot)
72 }
73
74 fn write_value<T: 'static>(&mut self, slot: Self::ValueSlot, value: T) {
75 SlotStorage::write_value(&mut self.root, slot, value);
76 }
77
78 fn remember<T: 'static>(&mut self, init: impl FnOnce() -> T) -> Owned<T> {
79 SlotStorage::remember(&mut self.root, init)
80 }
81
82 fn peek_node(&self) -> Option<NodeId> {
83 SlotStorage::peek_node(&self.root)
84 }
85
86 fn record_node(&mut self, id: NodeId) {
87 SlotStorage::record_node(&mut self.root, id);
88 }
89
90 fn advance_after_node_read(&mut self) {
91 SlotStorage::advance_after_node_read(&mut self.root);
92 }
93
94 fn step_back(&mut self) {
95 SlotStorage::step_back(&mut self.root);
96 }
97
98 fn finalize_current_group(&mut self) -> bool {
99 SlotStorage::finalize_current_group(&mut self.root)
100 }
101
102 fn reset(&mut self) {
103 SlotStorage::reset(&mut self.root);
104 }
105
106 fn flush(&mut self) {
107 SlotStorage::flush(&mut self.root);
108 }
109}
110
111impl HierarchicalSlotStorage {
112 pub fn debug_dump_groups(&self) -> Vec<(usize, Key, Option<ScopeId>, usize)> {
114 self.root.debug_dump_groups()
115 }
116
117 pub fn debug_dump_all_slots(&self) -> Vec<(usize, String)> {
119 self.root.debug_dump_all_slots()
120 }
121}