Class: Wasmtime::Store
- Inherits:
-
Object
- Object
- Wasmtime::Store
- Defined in:
- ext/src/ruby_api/store.rs
Overview
Represents a WebAssembly store.
Class Method Summary collapse
Instance Method Summary collapse
-
#add_fuel(fuel) ⇒ Nil
Adds fuel to the Store.
-
#consume_fuel(fuel) ⇒ Integer
Synthetically consumes fuel from this Store.
-
#data ⇒ Object
The passed in value in Store.new.
- #fuel_consumed ⇒ Integer, Nil
-
#set_epoch_deadline(ticks_beyond_current) ⇒ nil
Sets the epoch deadline to a certain number of ticks in the future.
Class Method Details
.new(engine, data = nil, wasi_ctx: nil) ⇒ Wasmtime::Store
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'ext/src/ruby_api/store.rs', line 97
pub fn new(args: &[Value]) -> Result<Self, Error> {
let args = scan_args::scan_args::<(&Engine,), (Option<Value>,), (), (), _, ()>(args)?;
let kw = scan_args::get_kwargs::<_, (), (Option<&WasiCtxBuilder>,), ()>(
args.keywords,
&[],
&[*WASI_CTX],
)?;
let (engine,) = args.required;
let (user_data,) = args.optional;
let user_data = user_data.unwrap_or_else(|| QNIL.into());
let wasi = match kw.optional.0 {
None => None,
Some(wasi_ctx_builder) => Some(wasi_ctx_builder.build_context()?),
};
let eng = engine.get();
let store_data = StoreData {
user_data,
wasi,
refs: Default::default(),
};
let store = Self {
inner: UnsafeCell::new(StoreImpl::new(eng, store_data)),
};
Ok(store)
}
|
Instance Method Details
#add_fuel(fuel) ⇒ Nil
Adds fuel to the Wasmtime::Store.
144 145 146 147 148 149 150 |
# File 'ext/src/ruby_api/store.rs', line 144
pub fn add_fuel(&self, fuel: u64) -> Result<Value, Error> {
unsafe { &mut *self.inner.get() }
.add_fuel(fuel)
.map_err(|e| error!("{}", e))?;
Ok(*QNIL)
}
|
#consume_fuel(fuel) ⇒ Integer
Synthetically consumes fuel from this Wasmtime::Store. Raises if there isn’t enough fuel left in the Wasmtime::Store, or when the Engine’s config does not have fuel enabled.
160 161 162 163 164 |
# File 'ext/src/ruby_api/store.rs', line 160
pub fn consume_fuel(&self, fuel: u64) -> Result<u64, Error> {
unsafe { &mut *self.inner.get() }
.consume_fuel(fuel)
.map_err(|e| error!("{}", e))
}
|
#data ⇒ Object
Returns The passed in value in new.
127 128 129 |
# File 'ext/src/ruby_api/store.rs', line 127
pub fn data(&self) -> Value {
self.context().data().user_data()
}
|
#fuel_consumed ⇒ Integer, Nil
Returns the amount of fuel consumed by this Wasmtime::Store’s execution so far, or nil
when the Engine’s config does not have fuel enabled.
135 136 137 |
# File 'ext/src/ruby_api/store.rs', line 135
pub fn fuel_consumed(&self) -> Option<u64> {
self.inner_ref().fuel_consumed()
}
|
#set_epoch_deadline(ticks_beyond_current) ⇒ nil
Sets the epoch deadline to a certain number of ticks in the future.
Raises if there isn’t enough fuel left in the Wasmtime::Store, or when the Engine’s config does not have fuel enabled.
176 177 178 |
# File 'ext/src/ruby_api/store.rs', line 176
pub fn set_epoch_deadline(&self, ticks_beyond_current: u64) {
unsafe { &mut *self.inner.get() }.set_epoch_deadline(ticks_beyond_current);
}
|