euv_core/reactive/id/impl.rs
1use super::*;
2
3/// Conversion helpers for `SlotId`.
4impl SlotId {
5 /// Converts the slot index into a `usize` for slice indexing.
6 ///
7 /// # Arguments
8 ///
9 /// - `&Self` - The slot identifier to convert.
10 ///
11 /// # Returns
12 ///
13 /// - `usize` - The zero-based vector index.
14 #[must_use]
15 pub fn as_usize(&self) -> usize {
16 self.get_index() as usize
17 }
18}
19
20/// Construction and inspection helpers for `SignalId`.
21impl SignalId {
22 /// Creates a new `SignalId` wrapping the provided `SlotId`.
23 ///
24 /// # Arguments
25 ///
26 /// - `SlotId` - The backing arena slot identifier.
27 ///
28 /// # Returns
29 ///
30 /// - `Self` - The constructed signal identifier.
31 #[must_use]
32 pub fn from_slot(slot: SlotId) -> Self {
33 Self(slot)
34 }
35
36 /// Returns the underlying `SlotId`.
37 ///
38 /// # Arguments
39 ///
40 /// - `&Self` - The signal identifier.
41 ///
42 /// # Returns
43 ///
44 /// - `SlotId` - The underlying slot identifier.
45 #[must_use]
46 pub fn slot(&self) -> SlotId {
47 self.0
48 }
49}
50
51/// Construction and inspection helpers for `MemoId`.
52impl MemoId {
53 /// Creates a new `MemoId` wrapping the provided `SlotId`.
54 ///
55 /// # Arguments
56 ///
57 /// - `SlotId` - The backing arena slot identifier.
58 ///
59 /// # Returns
60 ///
61 /// - `Self` - The constructed memo identifier.
62 #[must_use]
63 pub fn from_slot(slot: SlotId) -> Self {
64 Self(slot)
65 }
66
67 /// Returns the underlying `SlotId`.
68 ///
69 /// # Arguments
70 ///
71 /// - `&Self` - The memo identifier.
72 ///
73 /// # Returns
74 ///
75 /// - `SlotId` - The underlying slot identifier.
76 #[must_use]
77 pub fn slot(&self) -> SlotId {
78 self.0
79 }
80}
81
82/// Construction and inspection helpers for `EffectId`.
83impl EffectId {
84 /// Creates a new `EffectId` wrapping the provided `SlotId`.
85 ///
86 /// # Arguments
87 ///
88 /// - `SlotId` - The backing arena slot identifier.
89 ///
90 /// # Returns
91 ///
92 /// - `Self` - The constructed effect identifier.
93 #[must_use]
94 pub fn from_slot(slot: SlotId) -> Self {
95 Self(slot)
96 }
97
98 /// Returns the underlying `SlotId`.
99 ///
100 /// # Arguments
101 ///
102 /// - `&Self` - The effect identifier.
103 ///
104 /// # Returns
105 ///
106 /// - `SlotId` - The underlying slot identifier.
107 #[must_use]
108 pub fn slot(&self) -> SlotId {
109 self.0
110 }
111}
112
113/// Construction and inspection helpers for `ScopeId`.
114impl ScopeId {
115 /// Creates a new `ScopeId` wrapping the provided `SlotId`.
116 ///
117 /// # Arguments
118 ///
119 /// - `SlotId` - The backing arena slot identifier.
120 ///
121 /// # Returns
122 ///
123 /// - `Self` - The constructed scope identifier.
124 #[must_use]
125 pub fn from_slot(slot: SlotId) -> Self {
126 Self(slot)
127 }
128
129 /// Returns the underlying `SlotId`.
130 ///
131 /// # Arguments
132 ///
133 /// - `&Self` - The scope identifier.
134 ///
135 /// # Returns
136 ///
137 /// - `SlotId` - The underlying slot identifier.
138 #[must_use]
139 pub fn slot(&self) -> SlotId {
140 self.0
141 }
142}