Array
A fixed-size, indexable sequence of elements. Equivalent to Go’s [N]T.
The size is part of the type, so Array<byte, 2> and Array<byte, 4> are distinct types.
A list literal is a Slice by default, so an Array needs the annotation.
let rgb: Array<int, 3> = [255, 128, 0]Array<int, 3>let growable = [255, 128, 0]Slice<int>Compare to Slice
Array.length()
Section titled “Array.length()”Returns the size of the Array.
impl<T> Array<T> { fn length(self) -> int}let rgb: Array<int, 3> = [255, 128, 0]let size = rgb.length()3Array.get()
Section titled “Array.get()”Returns the element at index, or None if out of bounds.
impl<T> Array<T> { fn get(self, index: int) -> Option<T>}let rgb: Array<int, 3> = [255, 128, 0]let green = rgb.get(1)Some(128), or None when out of boundsArray.to_slice()
Section titled “Array.to_slice()”Copies the elements of the Array into a new Slice.
impl<T> Array<T> { fn to_slice(self) -> mut Slice<T>}let parts: Array<string, 3> = ["a", "b", "c"]let path = strings.Join(parts.to_slice(), "-")strings.Join takes a Slice, not an Array