From 41d6f48df482ca1eb614c9b69f9e9e6217f93216 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Tue, 27 Jun 2017 13:45:33 +0300 Subject: [PATCH 1/4] example for module() --- src/builder/code.rs | 2 +- src/builder/module.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) 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..c69d5dd 100644 --- a/src/builder/module.rs +++ b/src/builder/module.rs @@ -442,6 +442,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() } From 447c3db90def4661e7a032d43d749f123f7a549e Mon Sep 17 00:00:00 2001 From: NikVolf Date: Tue, 27 Jun 2017 13:54:51 +0300 Subject: [PATCH 2/4] import doc example --- src/builder/module.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/builder/module.rs b/src/builder/module.rs index c69d5dd..8e8d690 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) } From c72dfae3545353513d4e1c3f99246afea8f85c40 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Tue, 27 Jun 2017 14:12:57 +0300 Subject: [PATCH 3/4] export example --- src/builder/module.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/builder/module.rs b/src/builder/module.rs index 8e8d690..9c987a0 100644 --- a/src/builder/module.rs +++ b/src/builder/module.rs @@ -332,6 +332,24 @@ 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("import section to exist").entries().len(), 1); + /// ``` pub fn export(self) -> export::ExportBuilder { export::ExportBuilder::with_callback(self) } From 84ad965596b8d0a88596352042df6e6b68cacd41 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Tue, 27 Jun 2017 18:36:27 +0300 Subject: [PATCH 4/4] global example --- src/builder/module.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/builder/module.rs b/src/builder/module.rs index 9c987a0..742b05c 100644 --- a/src/builder/module.rs +++ b/src/builder/module.rs @@ -348,13 +348,27 @@ impl ModuleBuilder where F: Invoke { /// .build() /// .build(); /// - /// assert_eq!(module.export_section().expect("import section to exist").entries().len(), 1); + /// 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) }