Class: Wasmtime::Component::Component
- Inherits:
-
Object
- Object
- Wasmtime::Component::Component
- Defined in:
- ext/src/ruby_api/component.rs
Overview
Note:
Support for Wasm components in the Ruby bindings is experimental. APIs may change in the future.
Represents a WebAssembly component.
Class Method Summary collapse
-
.deserialize(engine, compiled) ⇒ Wasmtime::Component::Component
Instantiates a serialized component coming from either #serialize or Engine#precompile_component.
-
.deserialize_file(engine, path) ⇒ Wasmtime::Component::Component
Instantiates a serialized component from a file.
- .from_file(engine, path) ⇒ Wasmtime::Component::Component
-
.new(engine, wat_or_wasm) ⇒ Wasmtime::Component::Component
Creates a new component from the given binary data.
Instance Method Summary collapse
-
#serialize ⇒ String
Serialize the component.
Class Method Details
.deserialize(engine, compiled) ⇒ Wasmtime::Component::Component
Instantiates a serialized component coming from either #serialize or Engine#precompile_component.
The engine serializing and the engine deserializing must:
-
have the same configuration
-
be of the same gem version
89 90 91 92 93 94 |
# File 'ext/src/ruby_api/component.rs', line 89
pub fn deserialize(engine: &Engine, compiled: RString) -> Result<Self, Error> {
// SAFETY: this string is immediately copied and never moved off the stack
unsafe { ComponentImpl::deserialize(engine.get(), compiled.as_slice()) }
.map(Into::into)
.map_err(|e| error!("Could not deserialize component: {}", e))
}
|
.deserialize_file(engine, path) ⇒ Wasmtime::Component::Component
Instantiates a serialized component from a file.
104 105 106 107 108 |
# File 'ext/src/ruby_api/component.rs', line 104
pub fn deserialize_file(engine: &Engine, path: RString) -> Result<Self, Error> {
unsafe { ComponentImpl::deserialize_file(engine.get(), path.as_str()?) }
.map(Into::into)
.map_err(|e| error!("Could not deserialize component from file: {}", e))
}
|
.from_file(engine, path) ⇒ Wasmtime::Component::Component
68 69 70 71 72 73 74 75 76 |
# File 'ext/src/ruby_api/component.rs', line 68
pub fn from_file(engine: &Engine, path: RString) -> Result<Self, Error> {
let eng = engine.get();
let (path, _locked_str_guard) = path.as_locked_str()?;
// SAFETY: this string is immediately copied and never moved off the stack
let component = nogvl(|| ComponentImpl::from_file(eng, path))
.map_err(|e| error!("Could not build component from file: {}", e))?;
Ok(component.into())
}
|
.new(engine, wat_or_wasm) ⇒ Wasmtime::Component::Component
Creates a new component from the given binary data.
54 55 56 57 58 59 60 61 |
# File 'ext/src/ruby_api/component.rs', line 54
pub fn new(engine: &Engine, wat_or_wasm: RString) -> Result<Self, Error> {
let eng = engine.get();
let (locked_slice, _locked_slice_guard) = wat_or_wasm.as_locked_slice()?;
let component = nogvl(|| ComponentImpl::new(eng, locked_slice))
.map_err(|e| error!("Could not build component: {}", e))?;
Ok(component.into())
}
|
Instance Method Details
#serialize ⇒ String
Serialize the component.
114 115 116 117 118 119 120 |
# File 'ext/src/ruby_api/component.rs', line 114
pub fn serialize(&self) -> Result<RString, Error> {
let bytes = self.get().serialize();
bytes
.map(|bytes| RString::from_slice(&bytes))
.map_err(|e| error!("{:?}", e))
}
|