Class: Wasmtime::Caller

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

Instance Method Details

#add_fuel(fuel) ⇒ Nil

Adds fuel to the Store.

Parameters:

  • fuel (Integer)

    The fuel to add.

Returns:

  • (Nil)


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

Synthetically consumes fuel from this Store. Raises if there isn’t enough fuel left in the Store, or when the Engine’s config does not have fuel enabled.

Parameters:

  • fuel (Integer)

    The fuel to consume.

Returns:

  • (Integer)

    The remaining fuel.



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

See Also:



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_consumedInteger, Nil

Returns the amount of fuel consumed by this Store’s execution so far, or nil when the Engine’s config does not have fuel enabled.

Returns:

  • (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_dataObject

Returns the store’s data. Akin to Store#data.

Returns:

  • (Object)

    The store’s data (the object passed to Store.new).



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())
}