Class: Wasmtime::Caller
- Inherits:
-
Object
- Object
- Wasmtime::Caller
- Defined in:
- ext/src/ruby_api/caller.rs
Overview
Represents the Caller’s context within a Func execution. An instance of Caller is sent as the first parameter to Func’s implementation (the block argument in Func.new).
Instance Method Summary collapse
-
#add_fuel(fuel) ⇒ Nil
Adds fuel to the Store.
-
#consume_fuel(fuel) ⇒ Integer
Synthetically consumes fuel from this Store.
- #export(name) ⇒ Object
- #fuel_consumed ⇒ Integer, Nil
-
#store_data ⇒ Object
Returns the store’s data.
Instance Method Details
#add_fuel(fuel) ⇒ Nil
Adds fuel to the Store.
90 91 92 93 94 95 96 |
# File 'ext/src/ruby_api/caller.rs', line 90
pub fn add_fuel(&self, fuel: u64) -> Result<Value, Error> {
self.handle
.get_mut()
.and_then(|c| c.add_fuel(fuel).map_err(|e| error!("{}", e)))?;
Ok(*QNIL)
}
|
#consume_fuel(fuel) ⇒ Integer
101 102 103 104 105 |
# File 'ext/src/ruby_api/caller.rs', line 101
pub fn consume_fuel(&self, fuel: u64) -> Result<u64, Error> {
self.handle
.get_mut()
.and_then(|c| c.consume_fuel(fuel).map_err(|e| error!("{}", e)))
}
|
#export(name) ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'ext/src/ruby_api/caller.rs', line 70
pub fn export(rb_self: Obj<Caller<'a>>, name: RString) -> Result<Option<Extern<'a>>, Error> {
let caller = rb_self.get();
let inner = caller.handle.get_mut()?;
if let Some(export) = inner.get_export(unsafe { name.as_str() }?) {
export.wrap_wasmtime_type(rb_self.into()).map(Some)
} else {
Ok(None)
}
}
|
#fuel_consumed ⇒ Integer, Nil
83 84 85 |
# File 'ext/src/ruby_api/caller.rs', line 83
pub fn fuel_consumed(&self) -> Result<Option<u64>, Error> {
self.handle.get().map(|c| c.fuel_consumed())
}
|
#store_data ⇒ Object
Returns the store’s data. Akin to Store#data.
63 64 65 |
# File 'ext/src/ruby_api/caller.rs', line 63
pub fn store_data(&self) -> Result<Value, Error> {
self.context().map(|ctx| ctx.data().user_data())
}
|