diff --git a/src/builder/code.rs b/src/builder/code.rs index b76d941..b3cf39f 100644 --- a/src/builder/code.rs +++ b/src/builder/code.rs @@ -346,7 +346,7 @@ mod tests { .build() .bind(); - assert_eq!(result.len(), 1); + assert_eq!(result.len(), 1); } #[test] diff --git a/src/builder/module.rs b/src/builder/module.rs index c63b5a1..742b05c 100644 --- a/src/builder/module.rs +++ b/src/builder/module.rs @@ -301,6 +301,20 @@ impl ModuleBuilder where F: Invoke { } /// Import entry builder + /// # Examples + /// ``` + /// use parity_wasm::builder::module; + /// + /// let module = module() + /// .import() + /// .module("env") + /// .field("memory") + /// .external().memory(256, Some(256)) + /// .build() + /// .build(); + /// + /// assert_eq!(module.import_section().expect("import section to exist").entries().len(), 1); + /// ``` pub fn import(self) -> import::ImportBuilder { import::ImportBuilder::with_callback(self) } @@ -318,11 +332,43 @@ impl ModuleBuilder where F: Invoke { } /// Export entry builder + /// # Examples + /// ``` + /// use parity_wasm::builder::module; + /// use parity_wasm::elements::Opcode::*; + /// + /// let module = module() + /// .global() + /// .value_type().i32() + /// .init_expr(I32Const(0)) + /// .build() + /// .export() + /// .field("_zero") + /// .internal().global(0) + /// .build() + /// .build(); + /// + /// assert_eq!(module.export_section().expect("export section to exist").entries().len(), 1); + /// ``` pub fn export(self) -> export::ExportBuilder { export::ExportBuilder::with_callback(self) } /// Glboal entry builder + /// # Examples + /// ``` + /// use parity_wasm::builder::module; + /// use parity_wasm::elements::Opcode::*; + /// + /// let module = module() + /// .global() + /// .value_type().i32() + /// .init_expr(I32Const(0)) + /// .build() + /// .build(); + /// + /// assert_eq!(module.global_section().expect("global section to exist").entries().len(), 1); + /// ``` pub fn global(self) -> global::GlobalBuilder { global::GlobalBuilder::with_callback(self) } @@ -442,6 +488,22 @@ impl Invoke for ModuleBuilder } /// Start new module builder +/// # Examples +/// +/// ``` +/// use parity_wasm::builder; +/// +/// let module = builder::module() +/// .function() +/// .signature().param().i32().build() +/// .body().build() +/// .build() +/// .build(); +/// +/// assert_eq!(module.type_section().expect("type section to exist").types().len(), 1); +/// assert_eq!(module.function_section().expect("function section to exist").entries().len(), 1); +/// assert_eq!(module.code_section().expect("code section to exist").bodies().len(), 1); +/// ``` pub fn module() -> ModuleBuilder { ModuleBuilder::new() }