Class: Wasmtime::Extern

Inherits:
Object
  • Object
show all
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

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.

Parameters:

  • gvl (Boolean) (defaults to: true)

    When false, releases the GVL during the call so other Ruby threads run in parallel (each thread must use its own Store). Defaults to true.

Returns:

  • (Func)

    The exported function.



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_globalGlobal

Returns the exported global or raises a {ConversionError} when the export is not a global.

Returns:

  • (Global)

    The exported 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_memoryMemory

Returns the exported memory or raises a {ConversionError} when the export is not a memory.

Returns:

  • (Memory)

    The exported 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_tableTable

Returns the exported table or raises a {ConversionError} when the export is not a table.

Returns:

  • (Table)

    The exported 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)),
    }
}