Rename from_parity_wasm_module and doc it.
This commit is contained in:
parent
b27aaec434
commit
39a4f7cfef
|
@ -69,7 +69,7 @@ fn main() {
|
||||||
}).collect::<Vec<RuntimeValue>>()
|
}).collect::<Vec<RuntimeValue>>()
|
||||||
};
|
};
|
||||||
|
|
||||||
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:
|
// Intialize deserialized module. It adds module into It expects 3 parameters:
|
||||||
// - a name for the module
|
// - a name for the module
|
||||||
|
|
35
src/lib.rs
35
src/lib.rs
|
@ -237,7 +237,35 @@ pub struct Module {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Module {
|
impl Module {
|
||||||
pub fn from_module(module: parity_wasm::elements::Module) -> Result<Module, Error> {
|
/// 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<Module, Error> {
|
||||||
use validation::{validate_module, ValidatedModule};
|
use validation::{validate_module, ValidatedModule};
|
||||||
let ValidatedModule {
|
let ValidatedModule {
|
||||||
labels,
|
labels,
|
||||||
|
@ -250,10 +278,13 @@ impl Module {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create `Module` from a given buffer.
|
||||||
|
///
|
||||||
|
///
|
||||||
pub fn from_buffer<B: AsRef<[u8]>>(buffer: B) -> Result<Module, Error> {
|
pub fn from_buffer<B: AsRef<[u8]>>(buffer: B) -> Result<Module, Error> {
|
||||||
let module = parity_wasm::elements::deserialize_buffer(buffer.as_ref())
|
let module = parity_wasm::elements::deserialize_buffer(buffer.as_ref())
|
||||||
.map_err(|e: parity_wasm::elements::Error| Error::Validation(e.to_string()))?;
|
.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 {
|
pub(crate) fn module(&self) -> &parity_wasm::elements::Module {
|
||||||
|
|
Loading…
Reference in New Issue