pub type GcArray<T> = Gc<Array<T>>;Expand description
An owned root to a fixed-length, mutable WasmGC array.
This is an alias for Gc<Array<T>>. Elements implement GcValue and may
be scalars, GC references, nullable GC references, or crate::ExternRef.
Cloning an array shares its object; writes through either root are visible
through both. Getters copy element values rather than returning Rust
references into the array. Reading a reference element creates an independent
root to the stored object. Array equality compares elements; Gc::ref_eq
compares the array objects themselves.
Copies between GC arrays use array.copy, including overlapping ranges.
Copies between GC storage and Rust slices transfer elements one at a time:
built-in scalars use a generated Wasm loop, while other types use their
GcValue conversions in batches. Neither path exposes GC storage as
linear memory. The alloc feature adds to_vec and conversion from Vec<T>.
Array lengths and indices are 32-bit on both wasm32 and wasm64. Constructors
reject lengths above u32::MAX; an engine may fail smaller allocations too.
Roots have the same ownership and instance restrictions as Gc.
§Examples
Compile for a Wasm target and postprocess the resulting module with wasmgc
before executing this example.
use wasmgc::{Gc, GcArray};
let values = GcArray::from_slice([1i32, 2, 3]);
let alias = values.clone();
alias.set(1, 7);
assert_eq!(values.get(1), Some(7));
assert!(Gc::ref_eq(&values, &alias));
let copy = GcArray::<i32>::new_default(values.len());
copy.copy_from(0, &values, ..);
copy.set(1, 9);
assert_eq!(values.get(1), Some(7));
assert!(!Gc::ref_eq(&values, ©));Aliased Type§
pub struct GcArray<T> { /* private fields */ }