wasmer_types/
indexes.rs

1//! Helper functions and structures for the translation.
2use crate::entity::entity_impl;
3use core::u32;
4
5/// Index type of a function defined locally inside the WebAssembly module.
6#[derive(
7    Copy,
8    Clone,
9    PartialEq,
10    Eq,
11    Hash,
12    PartialOrd,
13    Ord,
14    Debug,
15    rkyv::Serialize,
16    rkyv::Deserialize,
17    rkyv::Archive,
18)]
19#[archive(as = "Self")]
20#[repr(transparent)]
21pub struct LocalFunctionIndex(u32);
22entity_impl!(LocalFunctionIndex);
23
24/// Index type of a table defined locally inside the WebAssembly module.
25#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
26pub struct LocalTableIndex(u32);
27entity_impl!(LocalTableIndex);
28
29/// Index type of a memory defined locally inside the WebAssembly module.
30#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
31pub struct LocalMemoryIndex(u32);
32entity_impl!(LocalMemoryIndex);
33
34/// Index type of a global defined locally inside the WebAssembly module.
35#[derive(
36    Copy,
37    Clone,
38    PartialEq,
39    Eq,
40    Hash,
41    PartialOrd,
42    Ord,
43    Debug,
44    rkyv::Serialize,
45    rkyv::Deserialize,
46    rkyv::Archive,
47)]
48#[archive(as = "Self")]
49#[repr(transparent)]
50pub struct LocalGlobalIndex(u32);
51entity_impl!(LocalGlobalIndex);
52
53/// Index type of a function (imported or local) inside the WebAssembly module.
54#[derive(
55    Copy,
56    Clone,
57    PartialEq,
58    Eq,
59    Hash,
60    PartialOrd,
61    Ord,
62    Debug,
63    rkyv::Serialize,
64    rkyv::Deserialize,
65    rkyv::Archive,
66)]
67#[archive(as = "Self")]
68#[repr(transparent)]
69pub struct FunctionIndex(u32);
70entity_impl!(FunctionIndex);
71
72/// Index type of a table (imported or local) inside the WebAssembly module.
73#[derive(
74    Copy,
75    Clone,
76    PartialEq,
77    Eq,
78    Hash,
79    PartialOrd,
80    Ord,
81    Debug,
82    rkyv::Serialize,
83    rkyv::Deserialize,
84    rkyv::Archive,
85)]
86#[archive(as = "Self")]
87#[repr(transparent)]
88pub struct TableIndex(u32);
89entity_impl!(TableIndex);
90
91/// Index type of a global variable (imported or local) inside the WebAssembly module.
92#[derive(
93    Copy,
94    Clone,
95    PartialEq,
96    Eq,
97    Hash,
98    PartialOrd,
99    Ord,
100    Debug,
101    rkyv::Serialize,
102    rkyv::Deserialize,
103    rkyv::Archive,
104)]
105#[archive(as = "Self")]
106#[repr(transparent)]
107pub struct GlobalIndex(u32);
108entity_impl!(GlobalIndex);
109
110/// Index type of a linear memory (imported or local) inside the WebAssembly module.
111#[derive(
112    Copy,
113    Clone,
114    PartialEq,
115    Eq,
116    Hash,
117    PartialOrd,
118    Ord,
119    Debug,
120    rkyv::Serialize,
121    rkyv::Deserialize,
122    rkyv::Archive,
123)]
124#[archive(as = "Self")]
125#[repr(transparent)]
126pub struct MemoryIndex(u32);
127entity_impl!(MemoryIndex);
128
129/// Index type of a signature (imported or local) inside the WebAssembly module.
130#[derive(
131    Copy,
132    Clone,
133    PartialEq,
134    Eq,
135    Hash,
136    PartialOrd,
137    Ord,
138    Debug,
139    rkyv::Serialize,
140    rkyv::Deserialize,
141    rkyv::Archive,
142)]
143#[archive(as = "Self")]
144#[repr(transparent)]
145pub struct SignatureIndex(u32);
146entity_impl!(SignatureIndex);
147
148/// Index type of a passive data segment inside the WebAssembly module.
149#[derive(
150    Copy,
151    Clone,
152    PartialEq,
153    Eq,
154    Hash,
155    PartialOrd,
156    Ord,
157    Debug,
158    rkyv::Serialize,
159    rkyv::Deserialize,
160    rkyv::Archive,
161)]
162#[archive(as = "Self")]
163#[repr(transparent)]
164pub struct DataIndex(u32);
165entity_impl!(DataIndex);
166
167/// Index type of a passive element segment inside the WebAssembly module.
168#[derive(
169    Copy,
170    Clone,
171    PartialEq,
172    Eq,
173    Hash,
174    PartialOrd,
175    Ord,
176    Debug,
177    rkyv::Serialize,
178    rkyv::Deserialize,
179    rkyv::Archive,
180)]
181#[archive(as = "Self")]
182#[repr(transparent)]
183pub struct ElemIndex(u32);
184entity_impl!(ElemIndex);
185
186/// Index type of a custom section inside a WebAssembly module.
187#[derive(
188    Copy,
189    Clone,
190    PartialEq,
191    Eq,
192    Hash,
193    PartialOrd,
194    Ord,
195    Debug,
196    rkyv::Serialize,
197    rkyv::Deserialize,
198    rkyv::Archive,
199)]
200#[archive(as = "Self")]
201#[repr(transparent)]
202pub struct CustomSectionIndex(u32);
203entity_impl!(CustomSectionIndex);
204
205/// An entity to export.
206#[derive(
207    Clone,
208    Debug,
209    Hash,
210    PartialEq,
211    Eq,
212    PartialOrd,
213    Ord,
214    rkyv::Serialize,
215    rkyv::Deserialize,
216    rkyv::Archive,
217)]
218#[archive(as = "Self")]
219#[repr(u8)]
220pub enum ExportIndex {
221    /// Function export.
222    Function(FunctionIndex),
223    /// Table export.
224    Table(TableIndex),
225    /// Memory export.
226    Memory(MemoryIndex),
227    /// Global export.
228    Global(GlobalIndex),
229}
230
231/// An entity to import.
232#[derive(
233    Clone,
234    Debug,
235    Hash,
236    PartialEq,
237    Eq,
238    PartialOrd,
239    Ord,
240    rkyv::Serialize,
241    rkyv::Deserialize,
242    rkyv::Archive,
243)]
244#[archive(as = "Self")]
245#[repr(u8)]
246pub enum ImportIndex {
247    /// Function import.
248    Function(FunctionIndex),
249    /// Table import.
250    Table(TableIndex),
251    /// Memory import.
252    Memory(MemoryIndex),
253    /// Global import.
254    Global(GlobalIndex),
255}