From 39a4f7cfef49956f6711e78d3459208822b6857d Mon Sep 17 00:00:00 2001 From: Sergey Pepyakin Date: Fri, 26 Jan 2018 17:47:51 +0300 Subject: [PATCH] Rename from_parity_wasm_module and doc it. --- examples/invoke.rs | 2 +- src/lib.rs | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/examples/invoke.rs b/examples/invoke.rs index 118fa42..f037287 100644 --- a/examples/invoke.rs +++ b/examples/invoke.rs @@ -69,7 +69,7 @@ fn main() { }).collect::>() }; - let loaded_module = wasmi::Module::from_module(module).expect("Module to be valid"); + let loaded_module = wasmi::Module::from_parity_wasm_module(module).expect("Module to be valid"); // Intialize deserialized module. It adds module into It expects 3 parameters: // - a name for the module diff --git a/src/lib.rs b/src/lib.rs index 1762a45..1c03e63 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -237,7 +237,35 @@ pub struct Module { } impl Module { - pub fn from_module(module: parity_wasm::elements::Module) -> Result { + /// Create `Module` from `parity_wasm::elements::Module`. + /// + /// This function will load, validate and prepare a `parity_wasm`'s `Module`. + /// + /// # Examples + /// + /// ``` + /// extern crate parity_wasm; + /// extern crate wasmi; + /// + /// use parity_wasm::builder; + /// use parity_wasm::elements; + /// + /// fn main() { + /// let parity_module = + /// builder::module() + /// .function() + /// .signature().with_param(elements::ValueType::I32).build() + /// .body().build() + /// .build() + /// .build(); + /// + /// let module = wasmi::Module::from_parity_wasm_module(parity_module) + /// .expect("parity-wasm builder generated invalid module!"); + /// + /// // Instantiate `module`, etc... + /// } + /// ``` + pub fn from_parity_wasm_module(module: parity_wasm::elements::Module) -> Result { use validation::{validate_module, ValidatedModule}; let ValidatedModule { labels, @@ -250,10 +278,13 @@ impl Module { }) } + /// Create `Module` from a given buffer. + /// + /// pub fn from_buffer>(buffer: B) -> Result { let module = parity_wasm::elements::deserialize_buffer(buffer.as_ref()) .map_err(|e: parity_wasm::elements::Error| Error::Validation(e.to_string()))?; - Module::from_module(module) + Module::from_parity_wasm_module(module) } pub(crate) fn module(&self) -> &parity_wasm::elements::Module {