diff --git a/src/builder/export.rs b/src/builder/export.rs index 379aacb..837043c 100644 --- a/src/builder/export.rs +++ b/src/builder/export.rs @@ -1,6 +1,7 @@ use super::invoke::{Invoke, Identity}; use elements; +/// Export entry builder pub struct ExportBuilder { callback: F, field: String, @@ -15,6 +16,7 @@ impl ExportBuilder { impl ExportBuilder { + /// New export entry builder in the specified chained context pub fn with_callback(callback: F) -> Self { ExportBuilder { callback: callback, @@ -23,22 +25,26 @@ impl ExportBuilder { } } + /// Set the field name of the export entry pub fn field(mut self, field: &str) -> Self { self.field = field.to_owned(); self } + /// Specify the internal module mapping for this entry pub fn with_internal(mut self, external: elements::Internal) -> Self { self.binding = external; self } + /// Start the internal builder for this export entry pub fn internal(self) -> ExportInternalBuilder { ExportInternalBuilder::with_callback(self) } } impl ExportBuilder where F: Invoke { + /// Finalize export entry builder spawning the resulting struct pub fn build(self) -> F::Result { self.callback.invoke(elements::ExportEntry::new(self.field, self.binding)) } @@ -51,12 +57,14 @@ impl Invoke for ExportBuilder { } } +/// Internal mapping builder for export entry pub struct ExportInternalBuilder { callback: F, binding: elements::Internal, } impl ExportInternalBuilder where F: Invoke { + /// New export entry internal mapping for the chained context pub fn with_callback(callback: F) -> Self { ExportInternalBuilder{ callback: callback, @@ -64,21 +72,25 @@ impl ExportInternalBuilder where F: Invoke { } } + /// Map to function by index pub fn func(mut self, index: u32) -> F::Result { self.binding = elements::Internal::Function(index); self.callback.invoke(self.binding) } + /// Map to memory pub fn memory(mut self, index: u32) -> F::Result { self.binding = elements::Internal::Memory(index); self.callback.invoke(self.binding) } + /// Map to table pub fn table(mut self, index: u32) -> F::Result { self.binding = elements::Internal::Table(index); self.callback.invoke(self.binding) } + /// Map to global pub fn global(mut self, index: u32) -> F::Result { self.binding = elements::Internal::Global(index); self.callback.invoke(self.binding) diff --git a/src/builder/mod.rs b/src/builder/mod.rs index bb21864..37e9808 100644 --- a/src/builder/mod.rs +++ b/src/builder/mod.rs @@ -16,7 +16,7 @@ pub use self::code::{ FunctionBuilder, TypeRefBuilder, FuncBodyBuilder, FunctionDefinition, }; pub use self::data::DataSegmentBuilder; -pub use self::export::{export, ExportBuilder}; +pub use self::export::{export, ExportBuilder, ExportInternalBuilder}; pub use self::global::{global, GlobalBuilder}; pub use self::import::{import, ImportBuilder}; pub use self::invoke::Identity;