Class: Wasmtime::Component::LinkerInstance

Inherits:
Object
  • Object
show all
Defined in:
ext/src/ruby_api/component/linker.rs

Overview

LinkerInstances are builder-style, ephemeral objects that can only be used within the block to which they get yielded. Calling methods outside of the block will raise.

Instance Method Summary collapse

Instance Method Details

#instance(name) {|instance| ... } ⇒ LinkerInstance

Defines a nested instance within the instance.

Parameters:

  • name (String)

Yields:

Yield Parameters:

Returns:



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'ext/src/ruby_api/component/linker.rs', line 203

fn instance(ruby: &Ruby, rb_self: Obj<Self>, name: RString) -> Result<Obj<Self>, Error> {
    let Ok(mut maybe_instance) = rb_self.inner.try_borrow_mut() else {
        return err!("LinkerInstance is not reentrant");
    };

    let inner = maybe_instance.get_mut()?;
    let nested_inner = inner
        .instance(unsafe { name.as_str()? })
        .map_err(|e| error!("{}", e))?;

    let nested_instance = Obj::wrap(LinkerInstance::from_inner(nested_inner));
    let block_result: Result<Value, _> = ruby.yield_value(nested_instance);
    nested_instance.take_inner();

    match block_result {
        Ok(_) => Ok(rb_self),
        Err(e) => Err(e),
    }
}

#module(name, mod) ⇒ Object

Parameters:



182
183
184
185
186
187
188
189
190
191
192
193
# File 'ext/src/ruby_api/component/linker.rs', line 182

fn module(rb_self: Obj<Self>, name: RString, module: &Module) -> Result<Obj<Self>, Error> {
    let Ok(mut maybe_instance) = rb_self.inner.try_borrow_mut() else {
        return err!("LinkerInstance is not reentrant");
    };

    let inner = maybe_instance.get_mut()?;
    inner
        .module(unsafe { name.as_str()? }, module.get())
        .map_err(|e| error!("{}", e))?;

    Ok(rb_self)
}