pub enum ElementType {
Int8,
Uint8,
Uint8Clamped,
Int16,
Uint16,
Int32,
Uint32,
Float16,
Float32,
Float64,
BigInt64,
BigUint64,
}Expand description
Which element type a view reads and writes.
Variants§
Int8
Int8Array
Uint8
Uint8Array
Uint8Clamped
Uint8ClampedArray
Int16
Int16Array
Uint16
Uint16Array
Int32
Int32Array
Uint32
Uint32Array
Float16
Float16Array
Float32
Float32Array
Float64
Float64Array
BigInt64
BigInt64Array
BigUint64
BigUint64Array
Implementations§
Source§impl ElementType
impl ElementType
Sourcepub fn is_bigint(self) -> bool
pub fn is_bigint(self) -> bool
Whether elements are BigInts rather than numbers.
The two behave differently in ways that reach most methods: the sort order, what a
literal element converts to, and whether a Number is a TypeError.
Sourcepub fn read(self, heap: &Heap, bytes: &[u8], offset: usize) -> Value
pub fn read(self, heap: &Heap, bytes: &[u8], offset: usize) -> Value
Read the element at offset.
A short buffer — only reachable if a view was built over a truncated one — reads as
0 rather than panicking, because a script must not be able to make the engine abort.
Sourcepub fn write(
self,
bytes: &mut [u8],
offset: usize,
value: &Value,
) -> Result<(), &'static str>
pub fn write( self, bytes: &mut [u8], offset: usize, value: &Value, ) -> Result<(), &'static str>
Store value into the element at offset.
value must already be the primitive this element type stores — a number for the
numeric types, a BigInt for the two BigInt ones. [write_element] is what
applies ToNumber/ToBigInt beforehand, because both can run script (valueOf)
and the storage borrow must not be held across that.
The Err carries the reason, which the caller turns into a TypeError.