Class: Wasmtime::Extern
- Inherits:
-
Object
- Object
- Wasmtime::Extern
- Defined in:
- ext/src/ruby_api/externals.rs
Overview
An external item to a WebAssembly module, or a list of what can possibly be exported from a Wasm module.
Instance Method Summary collapse
-
#to_func(gvl: true) ⇒ Func
Returns the exported function or raises a
{ConversionError}when the export is not a function. -
#to_global ⇒ Global
Returns the exported global or raises a
{ConversionError}when the export is not a global. -
#to_memory ⇒ Memory
Returns the exported memory or raises a
{ConversionError}when the export is not a memory. -
#to_table ⇒ Table
Returns the exported table or raises a
{ConversionError}when the export is not a table.
Instance Method Details
#to_func(gvl: true) ⇒ Func
Returns the exported function or raises a {ConversionError} when the export is not a
function.
Failing to respect the Store-per-thread requirement, when using gvl: false is highly unsafe and will result in undefined behavior.
141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'ext/src/ruby_api/externals.rs', line 141
pub fn to_func(ruby: &Ruby, rb_self: Obj<Self>, args: &[Value]) -> Result<Value, Error> {
let args = scan_args::scan_args::<(), (), (), (), _, ()>(args)?;
let kw = scan_args::get_kwargs::<_, (), (Option<bool>,), ()>(args.keywords, &[], &[*GVL])?;
match *rb_self {
Extern::Func(f) => match kw.optional.0 {
Some(false) => Ok(ruby.obj_wrap(f.without_gvl()).as_value()),
_ => Ok(f.as_value()),
},
_ => conversion_err!(Self::inner_class(rb_self), Func::class(ruby)),
}
}
|
#to_global ⇒ Global
Returns the exported global or raises a {ConversionError} when the export is not a global.
157 158 159 160 161 162 |
# File 'ext/src/ruby_api/externals.rs', line 157
pub fn to_global(ruby: &Ruby, rb_self: Obj<Self>) -> Result<Value, Error> {
match *rb_self {
Extern::Global(g) => Ok(g.as_value()),
_ => conversion_err!(Self::inner_class(rb_self), Global::class(ruby)),
}
}
|
#to_memory ⇒ Memory
Returns the exported memory or raises a {ConversionError} when the export is not a
memory.
168 169 170 171 172 173 |
# File 'ext/src/ruby_api/externals.rs', line 168
pub fn to_memory(ruby: &Ruby, rb_self: Obj<Self>) -> Result<Value, Error> {
match *rb_self {
Extern::Memory(m) => Ok(m.as_value()),
_ => conversion_err!(Self::inner_class(rb_self), Memory::class(ruby)),
}
}
|
#to_table ⇒ Table
Returns the exported table or raises a {ConversionError} when the export is not a table.
178 179 180 181 182 183 |
# File 'ext/src/ruby_api/externals.rs', line 178
pub fn to_table(ruby: &Ruby, rb_self: Obj<Self>) -> Result<Value, Error> {
match *rb_self {
Extern::Table(t) => Ok(t.as_value()),
_ => conversion_err!(Self::inner_class(rb_self), Table::class(ruby)),
}
}
|