pub struct Export { /* private fields */ }Expand description
The ๐พ๐๐๐๐๐๐ component of a module defines a set of exports that become accessible to the host environment once the module has been instantiated. Each export is labeled by a unique name. Exportable definitions are functions, tables, memories, and globals, which are referenced through a respective descriptor.
See https://webassembly.github.io/spec/core/syntax/modules.html#exports
ยงExamples
ยงTable
use wasm_ast::{Export, ExportDescription, Name};
let name = "functions";
let description = ExportDescription::Table(0);
let export = Export::new(name.into(), description.clone());
assert_eq!(export, Export::table(name.into(), 0));
assert_eq!(export.name(), &Name::new(String::from(name)));
assert_eq!(export.description(), &description);ยงMemory
use wasm_ast::{Export, ExportDescription, Name};
let name = "io";
let description = ExportDescription::Memory(1);
let export = Export::new(name.into(), description.clone());
assert_eq!(export, Export::memory(name.into(), 1));
assert_eq!(export.name(), &Name::new(String::from(name)));
assert_eq!(export.description(), &description);ยงFunction
use wasm_ast::{Export, ExportDescription, Name};
let name = "print";
let description = ExportDescription::Function(42);
let export = Export::new(name.into(), description.clone());
assert_eq!(export, Export::function(name.into(), 42));
assert_eq!(export.name(), &Name::new(String::from(name)));
assert_eq!(export.description(), &description);ยงGlobal
use wasm_ast::{Export, ExportDescription, Name};
let name = "functions";
let description = ExportDescription::Global(2);
let export = Export::new(name.into(), description.clone());
assert_eq!(export, Export::global(name.into(), 2));
assert_eq!(export.name(), &Name::new(String::from(name)));
assert_eq!(export.description(), &description);Implementationsยง
Sourceยงimpl Export
impl Export
Sourcepub fn new(name: Name, description: ExportDescription) -> Self
pub fn new(name: Name, description: ExportDescription) -> Self
Create a new instance of an Export with the given name and description.
Sourcepub fn table(name: Name, table: TableIndex) -> Self
pub fn table(name: Name, table: TableIndex) -> Self
Create a new instance of an Export with the given name and description for a table.
Sourcepub fn memory(name: Name, memory: MemoryIndex) -> Self
pub fn memory(name: Name, memory: MemoryIndex) -> Self
Create a new instance of an Export with the given name and description for a memory.
Sourcepub fn function(name: Name, function: FunctionIndex) -> Self
pub fn function(name: Name, function: FunctionIndex) -> Self
Create a new instance of an Export with the given name and description for a function.
Sourcepub fn global(name: Name, global: GlobalIndex) -> Self
pub fn global(name: Name, global: GlobalIndex) -> Self
Create a new instance of an Export with the given name and description for a global.
Sourcepub fn description(&self) -> &ExportDescription
pub fn description(&self) -> &ExportDescription
The description of the table.