Skip to main content

array

fixed array [T; N]

stack-allocated, fixed size known at compile time.

let a: [int32; 3] = [1, 2, 3];

fields

  • .ptr — raw pointer to the data
  • .len — number of elements

dynamic array Array[T]

heap-allocated, growable.

let mut b: Array[int32] = [1, 2, 3];
let mut c = Array.new([1, 2, 3]);
let mut d = Array.new([1, 2, 3], arena); // with arena allocator

methods

methoddescription
.len()number of elements
.append(val)push value to the end
.remove(val)remove first occurrence of val
.pop(idx?)remove and return element at idx (default: last)
.drop()free memory — manual mode only

examples

let mut b: Array[int32] = [1, 2, 3];

b.append(4); // [1, 2, 3, 4]
b.remove(2); // [1, 3, 4]
let x = b.pop(); // x == 4, b == [1, 3]
let y = b.pop(0); // y == 1, b == [3]