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
-
#data ⇒ Object
The passed in value in Store.new.
-
#get_fuel ⇒ Integer
Returns the amount of fuel in the Store.
-
#linear_memory_limit_hit? ⇒ Boolean
Returns whether the linear memory limit has been hit.
-
#max_linear_memory_consumed ⇒ Integer
Returns the maximum linear memory consumed.
-
#set_epoch_deadline(ticks_beyond_current) ⇒ nil
Sets the epoch deadline to a certain number of ticks in the future.
-
#set_fuel(fuel) ⇒ Object
Sets fuel to the Store.
Class Method Details
.new(engine, data = nil, wasi_config: nil, wasi_p1_config: nil, limits: nil) ⇒ Wasmtime::Store
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'ext/src/ruby_api/store.rs', line 150
pub fn new(args: &[Value]) -> Result<Self, Error> {
let ruby = Ruby::get().unwrap();
let args = scan_args::scan_args::<(&Engine,), (Option<Value>,), (), (), _, ()>(args)?;
let kw = scan_args::get_kwargs::<
_,
(),
(Option<&WasiConfig>, Option<&WasiConfig>, Option<RHash>),
(),
>(
args.keywords,
&[],
&[*WASI_CONFIG, *WASI_P1_CONFIG, *LIMITS],
)?;
let (engine,) = args.required;
let (user_data,) = args.optional;
let user_data = user_data.unwrap_or_else(|| ().into_value_with(&ruby));
let wasi_config = kw.optional.0;
let wasi_p1_config = kw.optional.1;
let wasi = wasi_config
.map(|wasi_config| wasi_config.build(&ruby))
.transpose()?;
let wasi_p1 = wasi_p1_config
.map(|wasi_config| wasi_config.build_p1(&ruby))
.transpose()?;
let limiter = match kw.optional.2 {
None => StoreLimitsBuilder::new(),
Some(limits) => hash_to_store_limits_builder(&ruby, limits)?,
}
.build();
let limiter = TrackingResourceLimiter::new(limiter);
let eng = engine.get();
let store_data = StoreData {
user_data,
wasi_p1,
wasi,
refs: Default::default(),
last_error: Default::default(),
store_limits: limiter,
resource_table: Default::default(),
};
let store = Self {
inner: UnsafeCell::new(StoreImpl::new(eng, store_data)),
};
unsafe { &mut *store.inner.get() }.limiter(|data| &mut data.store_limits);
Ok(store)
}
|
Instance Method Details
#data ⇒ Object
Returns The passed in value in new.
205 206 207 |
# File 'ext/src/ruby_api/store.rs', line 205
pub fn data(&self) -> Value {
self.context().data().user_data()
}
|
#get_fuel ⇒ Integer
Returns the amount of fuel in the Wasmtime::Store.
214 215 216 |
# File 'ext/src/ruby_api/store.rs', line 214
pub fn get_fuel(&self) -> Result<u64, Error> {
self.inner_ref().get_fuel().map_err(|e| error!("{}", e))
}
|
#linear_memory_limit_hit? ⇒ Boolean
Returns whether the linear memory limit has been hit.
250 251 252 |
# File 'ext/src/ruby_api/store.rs', line 250
pub fn linear_memory_limit_hit(&self) -> bool {
self.context().data().store_limits.linear_memory_limit_hit()
}
|
#max_linear_memory_consumed ⇒ Integer
Returns the maximum linear memory consumed.
258 259 260 261 262 263 |
# File 'ext/src/ruby_api/store.rs', line 258
pub fn max_linear_memory_consumed(&self) -> usize {
self.context()
.data()
.store_limits
.max_linear_memory_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.
241 242 243 |
# File 'ext/src/ruby_api/store.rs', line 241
pub fn set_epoch_deadline(&self, ticks_beyond_current: u64) {
unsafe { &mut *self.inner.get() }.set_epoch_deadline(ticks_beyond_current);
}
|
#set_fuel(fuel) ⇒ Object
Sets fuel to the Wasmtime::Store.
223 224 225 226 227 228 229 |
# File 'ext/src/ruby_api/store.rs', line 223
pub fn set_fuel(&self, fuel: u64) -> Result<(), Error> {
unsafe { &mut *self.inner.get() }
.set_fuel(fuel)
.map_err(|e| error!("{}", e))?;
Ok(())
}
|