Class: Wasmtime::Module
- Inherits:
-
Object
- Object
- Wasmtime::Module
- Defined in:
- ext/src/ruby_api/module.rs
Overview
Represents a WebAssembly module.
Class Method Summary collapse
-
.deserialize(engine, compiled) ⇒ Wasmtime::Module
Instantiates a serialized module coming from either #serialize or Engine#precompile_module.
-
.deserialize_file(engine, path) ⇒ Wasmtime::Module
Instantiates a serialized module from a file.
- .from_file(engine, path) ⇒ Wasmtime::Module
- .new(engine, wat_or_wasm) ⇒ Wasmtime::Module
Instance Method Summary collapse
-
#serialize ⇒ String
Serialize the module.
Class Method Details
.deserialize(engine, compiled) ⇒ Wasmtime::Module
Instantiates a serialized module coming from either #serialize or Engine#precompile_module.
The engine serializing and the engine deserializing must:
-
have the same configuration
-
be of the same gem version
55 56 57 58 59 60 |
# File 'ext/src/ruby_api/module.rs', line 55
pub fn deserialize(engine: &Engine, compiled: RString) -> Result<Self, Error> {
// SAFETY: this string is immediately copied and never moved off the stack
unsafe { ModuleImpl::deserialize(engine.get(), compiled.as_slice()) }
.map(|module| Self { inner: module })
.map_err(|e| error!("Could not deserialize module: {}", e))
}
|
.deserialize_file(engine, path) ⇒ Wasmtime::Module
Instantiates a serialized module from a file.
70 71 72 73 74 |
# File 'ext/src/ruby_api/module.rs', line 70
pub fn deserialize_file(engine: &Engine, path: RString) -> Result<Self, Error> {
unsafe { ModuleImpl::deserialize_file(engine.get(), path.as_str()?) }
.map(|module| Self { inner: module })
.map_err(|e| error!("Could not deserialize module from file: {}", e))
}
|
.from_file(engine, path) ⇒ Wasmtime::Module
35 36 37 38 39 40 41 42 |
# File 'ext/src/ruby_api/module.rs', line 35
pub fn from_file(engine: &Engine, path: RString) -> Result<Self, Error> {
let eng = engine.get();
// SAFETY: this string is immediately copied and never moved off the stack
let module = ModuleImpl::from_file(eng, unsafe { path.as_str()? })
.map_err(|e| error!("Could not build module from file: {}", e))?;
Ok(Self { inner: module })
}
|
.new(engine, wat_or_wasm) ⇒ Wasmtime::Module
21 22 23 24 25 26 27 28 |
# File 'ext/src/ruby_api/module.rs', line 21
pub fn new(engine: &Engine, wat_or_wasm: RString) -> Result<Self, Error> {
let eng = engine.get();
// SAFETY: this string is immediately copied and never moved off the stack
let module = ModuleImpl::new(eng, unsafe { wat_or_wasm.as_slice() })
.map_err(|e| error!("Could not build module: {}", e))?;
Ok(Self { inner: module })
}
|
Instance Method Details
#serialize ⇒ String
Serialize the module.
80 81 82 83 84 85 |
# File 'ext/src/ruby_api/module.rs', line 80
pub fn serialize(&self) -> Result<RString, Error> {
self.get()
.serialize()
.map(|bytes| RString::from_slice(&bytes))
.map_err(|e| error!("{:?}", e))
}
|