MCPcopy Index your code
hub / github.com/explodingcamera/tinywasm / exports

Method exports

crates/types/src/lib.rs:167–279  ·  view source on GitHub ↗

Returns an iterator over the module's export descriptors. The returned data mirrors the module's export section and preserves order.

(&self)

Source from the content-addressed store, hash-verified

165 ///
166 /// The returned data mirrors the module's export section and preserves order.
167 pub fn exports(&self) -> impl Iterator<Item = ModuleExport<'_>> {
168 fn imported_count(module: &ModuleInner, kind: ExternalKind) -> usize {
169 module
170 .imports
171 .iter()
172 .filter(|import| {
173 matches!(
174 (kind, &import.kind),
175 (ExternalKind::Func, ImportKind::Function(_))
176 | (ExternalKind::Table, ImportKind::Table(_))
177 | (ExternalKind::Memory, ImportKind::Memory(_))
178 | (ExternalKind::Global, ImportKind::Global(_))
179 )
180 })
181 .count()
182 }
183
184 fn imported_func_type(module: &ModuleInner, function_index: usize) -> Option<&FuncType> {
185 let mut seen = 0usize;
186 for import in module.imports.iter() {
187 if let ImportKind::Function(type_idx) = import.kind {
188 if seen == function_index {
189 return module.func_types.get(type_idx as usize).map(|ty| &**ty);
190 }
191 seen += 1;
192 }
193 }
194 None
195 }
196
197 fn imported_table_type(module: &ModuleInner, table_index: usize) -> Option<&TableType> {
198 let mut seen = 0usize;
199 for import in module.imports.iter() {
200 if let ImportKind::Table(table_ty) = &import.kind {
201 if seen == table_index {
202 return Some(table_ty);
203 }
204 seen += 1;
205 }
206 }
207 None
208 }
209
210 fn imported_memory_type(module: &ModuleInner, memory_index: usize) -> Option<&MemoryType> {
211 let mut seen = 0usize;
212 for import in module.imports.iter() {
213 if let ImportKind::Memory(memory_ty) = &import.kind {
214 if seen == memory_index {
215 return Some(memory_ty);
216 }
217 seen += 1;
218 }
219 }
220 None
221 }
222
223 fn imported_global_type(module: &Module, global_index: usize) -> Option<&GlobalType> {
224 let mut seen = 0usize;

Callers 2

runFunction · 0.45
runFunction · 0.45

Calls 5

TableClass · 0.85
MemoryClass · 0.85
as_refMethod · 0.80
GlobalClass · 0.70
getMethod · 0.45

Tested by 1

runFunction · 0.36