Class: Wasmtime::Component::Linker
- Inherits:
-
Object
- Object
- Wasmtime::Component::Linker
- Defined in:
- ext/src/ruby_api/component/linker.rs
Overview
Class Method Summary collapse
Instance Method Summary collapse
-
#instance(name) {|instance| ... } ⇒ Linker
Define items at the provided namespace in this Linker.
- #instantiate(store, component) ⇒ Instance
-
#root {|instance| ... } ⇒ Linker
Define items in the root of this Linker.
Class Method Details
.new(engine) ⇒ Linker
40 41 42 43 44 45 46 |
# File 'ext/src/ruby_api/component/linker.rs', line 40
pub fn new(engine: &Engine) -> Result<Self, Error> {
let linker = LinkerImpl::new(engine.get());
Ok(Linker {
inner: RefCell::new(linker),
refs: RefCell::new(Vec::new()),
})
}
|
Instance Method Details
#instance(name) {|instance| ... } ⇒ Linker
Define items at the provided namespace in this Wasmtime::Component::Linker.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'ext/src/ruby_api/component/linker.rs', line 78
pub fn instance(ruby: &Ruby, rb_self: Obj<Self>, name: RString) -> Result<Obj<Self>, Error> {
let mut inner = rb_self.inner.borrow_mut();
let instance = inner
.instance(unsafe { name.as_str() }?)
.map_err(|e| error!("{}", e))?;
let instance = Obj::wrap(LinkerInstance::from_inner(instance));
let block_result: Result<Value, _> = ruby.yield_value(instance);
instance.take_inner();
match block_result {
Ok(_) => Ok(rb_self),
Err(e) => Err(e),
}
}
|
#instantiate(store, component) ⇒ Instance
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'ext/src/ruby_api/component/linker.rs', line 102
fn instantiate(
_ruby: &Ruby,
rb_self: Obj<Self>,
store: Obj<Store>,
component: &Component,
) -> Result<Instance, Error> {
let inner = rb_self.inner.borrow();
inner
.instantiate(store.context_mut(), component.get())
.map(|instance| {
rb_self
.refs
.borrow()
.iter()
.for_each(|value| store.retain(*value));
Instance::from_inner(store, instance)
})
.map_err(|e| error!("{}", e))
}
}
|
#root {|instance| ... } ⇒ Linker
Define items in the root of this Wasmtime::Component::Linker.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'ext/src/ruby_api/component/linker.rs', line 55
pub fn root(ruby: &Ruby, rb_self: Obj<Self>) -> Result<Obj<Self>, Error> {
let Ok(mut inner) = rb_self.inner.try_borrow_mut() else {
return err!("Linker is not reentrant");
};
let instance = Obj::wrap(LinkerInstance::from_inner(inner.root()));
let block_result: Result<Value, _> = ruby.yield_value(instance);
instance.take_inner();
match block_result {
Ok(_) => Ok(rb_self),
Err(e) => Err(e),
}
}
|