wasmer_runtime_core_fl/
export.rs1use crate::{
4 error,
5 global::Global,
6 instance::{Exports, InstanceInner},
7 memory::Memory,
8 module::ExportIndex,
9 module::ModuleInner,
10 table::Table,
11 types::FuncSig,
12 vm,
13};
14use indexmap::map::Iter as IndexMapIter;
15use std::{ptr::NonNull, sync::Arc};
16
17#[derive(Debug, Copy, Clone)]
19pub enum Context {
20 External(*mut vm::Ctx),
22
23 ExternalWithEnv(*mut vm::Ctx, Option<NonNull<vm::FuncEnv>>),
26
27 Internal,
29}
30
31unsafe impl Send for Context {}
33
34#[derive(Debug, Clone)]
36pub enum Export {
37 Function {
39 func: FuncPointer,
41 ctx: Context,
43 signature: Arc<FuncSig>,
45 },
46 Memory(Memory),
48 Table(Table),
50 Global(Global),
52}
53
54#[derive(Debug, Clone)]
56pub struct FuncPointer(*const vm::Func);
57
58unsafe impl Send for FuncPointer {}
60
61impl FuncPointer {
62 pub unsafe fn new(f: *const vm::Func) -> Self {
66 FuncPointer(f)
67 }
68
69 pub(crate) fn inner(&self) -> *const vm::Func {
70 self.0
71 }
72}
73
74pub struct ExportIter<'a> {
76 inner: &'a InstanceInner,
77 iter: IndexMapIter<'a, String, ExportIndex>,
78 module: &'a ModuleInner,
79}
80
81impl<'a> ExportIter<'a> {
82 pub(crate) fn new(module: &'a ModuleInner, inner: &'a InstanceInner) -> Self {
83 Self {
84 inner,
85 iter: module.info.exports.iter(),
86 module,
87 }
88 }
89}
90
91impl<'a> Iterator for ExportIter<'a> {
92 type Item = (String, Export);
93 fn next(&mut self) -> Option<(String, Export)> {
94 let (name, export_index) = self.iter.next()?;
95 Some((
96 name.clone(),
97 self.inner.get_export_from_index(&self.module, export_index),
98 ))
99 }
100}
101
102pub trait Exportable<'a>: Sized {
104 fn get_self(exports: &'a Exports, name: &str) -> error::ResolveResult<Self>;
107}