Class: Wasmtime::Table
- Inherits:
-
Object
- Object
- Wasmtime::Table
- Defined in:
- ext/src/ruby_api/table.rs
Overview
Represents a WebAssembly table.
Class Method Summary collapse
Instance Method Summary collapse
-
#get(index) ⇒ Object?
Returns the table element value at
index
, ornil
if index is out of bound. -
#grow(delta, initial) ⇒ void
Grows the size of this table by
delta
. -
#max_size ⇒ Integer?
The maximum size of this table.
-
#min_size ⇒ Integer
The minimum size of this table.
-
#set(index, value) ⇒ void
Sets the table entry at
index
tovalue
. -
#size ⇒ Integer
The size of the table.
-
#type ⇒ Symbol
The Wasm type of the elements of this table.
Class Method Details
.new(store, type, initial, min_size:, max_size: nil) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'ext/src/ruby_api/table.rs', line 57
pub fn new(args: &[Value]) -> Result<Self, Error> {
let args = scan_args::scan_args::<(Obj<Store>, Symbol, Value), (), (), (), _, ()>(args)?;
let kw = scan_args::get_kwargs::<_, (u32,), (Option<u32>,), ()>(
args.keywords,
&[*MIN_SIZE],
&[*MAX_SIZE],
)?;
let (s, value_type, default) = args.required;
let (min,) = kw.required;
let (max,) = kw.optional;
let store = s.get();
let wasm_type = value_type.to_val_type()?;
let wasm_default = default.to_wasm_val(&wasm_type)?;
let inner = TableImpl::new(
store.context_mut(),
TableType::new(wasm_type, min, max),
wasm_default,
)
.map_err(|e| error!("{}", e))?;
let table = Self {
store: s.into(),
inner,
};
table.retain_non_nil_extern_ref(default)?;
Ok(table)
}
|
Instance Method Details
#get(index) ⇒ Object?
Returns the table element value at index
, or nil
if index is out of bound.
117 118 119 120 121 122 |
# File 'ext/src/ruby_api/table.rs', line 117
pub fn get(&self, index: u32) -> Result<Value, Error> {
match self.inner.get(self.store.context_mut()?, index) {
Some(wasm_val) => wasm_val.to_ruby_value(&self.store),
None => Ok(*QNIL),
}
}
|
#grow(delta, initial) ⇒ void
This method returns an undefined value.
Grows the size of this table by delta
. Raises if the table grows beyond its limit.
153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'ext/src/ruby_api/table.rs', line 153
pub fn grow(&self, delta: u32, initial: Value) -> Result<u32, Error> {
self.inner
.grow(
self.store.context_mut()?,
delta,
initial.to_wasm_val(&self.value_type()?)?,
)
.map_err(|e| error!("{}", e))
.and_then(|result| {
self.retain_non_nil_extern_ref(initial)?;
Ok(result)
})
}
|
#max_size ⇒ Integer?
Returns The maximum size of this table.
107 108 109 |
# File 'ext/src/ruby_api/table.rs', line 107
pub fn max_size(&self) -> Result<Option<u32>, Error> {
self.ty().map(|ty| ty.maximum())
}
|
#min_size ⇒ Integer
Returns The minimum size of this table.
101 102 103 |
# File 'ext/src/ruby_api/table.rs', line 101
pub fn min_size(&self) -> Result<u32, Error> {
self.ty().map(|ty| ty.minimum())
}
|
#set(index, value) ⇒ void
This method returns an undefined value.
Sets the table entry at index
to value
.
131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'ext/src/ruby_api/table.rs', line 131
pub fn set(&self, index: u32, value: Value) -> Result<(), Error> {
self.inner
.set(
self.store.context_mut()?,
index,
value.to_wasm_val(&self.value_type()?)?,
)
.map_err(|e| error!("{}", e))
.and_then(|result| {
self.retain_non_nil_extern_ref(value)?;
Ok(result)
})
}
|
#size ⇒ Integer
Returns The size of the table.
169 170 171 |
# File 'ext/src/ruby_api/table.rs', line 169
pub fn size(&self) -> Result<u32, Error> {
Ok(self.inner.size(self.store.context()?))
}
|
#type ⇒ Symbol
Returns The Wasm type of the elements of this table.
95 96 97 |
# File 'ext/src/ruby_api/table.rs', line 95
pub fn type_(&self) -> Result<Symbol, Error> {
self.ty().map(|ty| ty.element().to_sym())
}
|