Skip to main content

GcArray

Type Alias GcArray 

Source
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, &copy));

Aliased Type§

pub struct GcArray<T> { /* private fields */ }

Trait Implementations§

Source§

impl<T: GcValue + Debug> Debug for GcArray<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: GcValue> Default for GcArray<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: GcValue + Eq> Eq for GcArray<T>

Source§

impl<T: GcValue, const N: usize> From<&[T; N]> for GcArray<T>

Source§

fn from(values: &[T; N]) -> Self

Converts to this type from the input type.
Source§

impl<T: GcValue> From<&[T]> for GcArray<T>

Source§

fn from(values: &[T]) -> Self

Converts to this type from the input type.
Source§

impl<T: GcValue> From<Vec<T>> for GcArray<T>

Available on crate feature alloc only.
Source§

fn from(values: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: GcValue, const N: usize> From<[T; N]> for GcArray<T>

Source§

fn from(values: [T; N]) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: GcValue> IntoIterator for &'a GcArray<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = GcArrayIter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: GcValue + PartialEq> PartialEq for GcArray<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: GcValue + PartialEq> PartialEq<&[T]> for GcArray<T>

Source§

fn eq(&self, other: &&[T]) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: GcValue + PartialEq, const N: usize> PartialEq<[T; N]> for GcArray<T>

Source§

fn eq(&self, other: &[T; N]) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: GcValue + PartialEq> PartialEq<[T]> for GcArray<T>

Source§

fn eq(&self, other: &[T]) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more