std/array

Types

Array

pub type Array[T]

Growable ordered sequence of T.

Array.clone

pub pure fn Array[T: Copy].clone(self) -> Array[T]

A copy of the array; the elements are Copy, so nothing is shared.

Array.tryClone

pub pure fn Array[T: Copy].tryClone(self) -> Result[Array[T], AllocError]

A copy of the array, or AllocError when the allocator refuses (clone panics instead).

Array.cloneWith

pub pure fn Array[T].cloneWith(self, f: fn(&T) -> T) -> Array[T]

A copy of the array whose elements f builds from a borrow of each original.

Array.tryCloneWith

pub pure fn Array[T].tryCloneWith(self, f: fn(&T) -> T) -> Result[Array[T], AllocError]

A copy whose elements f builds from a borrow of each original, or AllocError when the allocator refuses (cloneWith panics instead).

Array.empty

pub pure fn Array.empty[T]() -> Array[T]

Creates an empty array.

Array.tryEmpty

pub pure fn Array.tryEmpty[T]() -> Result[Array[T], AllocError]

An empty array, or AllocError when the allocator refuses (empty panics instead).

Array.of

pub pure fn Array.of[T](items: ...T) -> Array[T]

Creates an array holding the given items in order.

Array.fill

pub pure fn Array.fill[T: Copy](value: T, n: usize) -> Array[T]

n copies of value.

Array.tryFill

pub pure fn Array.tryFill[T: Copy](value: T, n: usize) -> Result[Array[T], AllocError]

n copies of value, or AllocError when the allocator refuses (fill panics instead).

Array.tryWithCapacity

pub pure fn Array.tryWithCapacity[T](capacity: usize) -> Result[Array[T], AllocError]

An empty array with room for capacity elements, or AllocError when the allocator refuses.

Array.tryReverse

pub pure fn Array[T: Copy].tryReverse(self) -> Result[Array[T], AllocError]

Copy with the elements in reverse order, or AllocError when the allocator refuses (reverse panics instead).

Array.push

pub pure fn Array[T].push(mut self, item: T)

Appends item at the end; panics when memory runs out (tryPush reports it instead).

Array.tryPush

pub pure fn Array[T].tryPush(mut self, item: T) -> Result[Void, AllocError]

Appends item, or returns AllocError when memory runs out.

Array.tryReserve

pub pure fn Array[T].tryReserve(mut self, extra: usize) -> Result[Void, AllocError]

Reserves room for extra more elements without adding any.

Array.appendAll

pub pure fn Array[T].appendAll(mut self, other: Array[T])

Moves the elements of other into self.

Array.tryAppendAll

pub pure fn Array[T].tryAppendAll(mut self, other: Array[T]) -> Result[Void, AllocError]

Moves the elements of other into self, or AllocError when the allocator refuses.

Array.insertAt

pub pure fn Array[T].insertAt(mut self, index: usize, item: T) -> Bool

Inserts item before the element at index, shifting the later ones up; false when index is past the end. Panics when memory runs out (tryInsertAt reports it instead).

Array.tryInsertAt

pub pure fn Array[T].tryInsertAt(mut self, index: usize, item: T) -> Result[Bool, AllocError]

Same as insertAt, or AllocError when the allocator refuses; the array is unchanged then.

Array.len

pub pure noalloc fn Array[T].len(self) -> usize

Number of elements.

Array.get

pub pure noalloc fn Array[T: Copy].get(self, index: usize) -> T?

A copy of the element at index, or None when index is out of range.

Array.with

pub pure fn Array[T].with[R](self, index: usize, f: fn(&T) -> R) -> R?

Calls f once with a borrow of the element at index and does not keep it (f is non-escaping); None when index is out of range.

Array.withMut

pub pure fn Array[T].withMut[R](mut self, index: usize, f: fn(&mut T) -> R) -> R?

Calls f once with an exclusive borrow of the element at index, so f can mutate it in place, and does not keep it; None when index is out of range.

Array.takeAt

pub pure fn Array[T].takeAt(mut self, index: usize) -> T?

Moves the element at index out, closing the gap; None when index is out of range.

Array.take

pub pure fn Array[T: Copy].take(self, count: usize) -> Array[T]

The first count elements, or all of them when the array is shorter.

Array.tryTake

pub pure fn Array[T: Copy].tryTake(self, count: usize) -> Result[Array[T], AllocError]

The first count elements, or all of them when the array is shorter; AllocError when the allocator refuses (take panics instead).

Array.map

pub pure fn Array[T].map[U](self, f: fn(&T) -> U) -> Array[U]

Applies f to a borrow of every element and collects the results in order; f cannot move an element out (use for to consume them) and is not kept.

Array.tryMap

pub pure fn Array[T].tryMap[U](self, f: fn(&T) -> U) -> Result[Array[U], AllocError]

Applies f to every element and collects the results in order, or AllocError when the allocator refuses (map panics instead).

Array.filter

pub pure fn Array[T: Copy].filter(self, keep: fn(&T) -> Bool) -> Array[T]

Elements for which keep returns true, in the original order.

Array.tryFilter

pub pure fn Array[T: Copy].tryFilter(self, keep: fn(&T) -> Bool) -> Result[Array[T], AllocError]

Elements for which keep returns true, in the original order, or AllocError when the allocator refuses (filter panics instead).

Array.fold

pub pure fn Array[T].fold[A, F: FnMut[fn(A, &T) -> A]](self, init: A, mut step: F) -> A

Reduces the array left to right, starting from init; step borrows each element and cannot move it out (use for to consume them).

Array.equals

pub pure fn Array[T: Eq].equals(self, other: &Array[T]) -> Bool

Element-wise equality; satisfies Eq when T does.

Array.hash

pub pure fn Array[T: Hash].hash(self) -> u64

Hash over the elements in order; satisfies Hash when T does.

Array.contains

pub pure fn Array[T: Eq].contains(self, item: T) -> Bool

Whether some element equals item.

Array.reverse

pub pure fn Array[T: Copy].reverse(self) -> Array[T]

Copy with the elements in reverse order.

Array.first

pub pure noalloc fn Array[T: Copy].first(self) -> T?

The first element, or None when the array is empty.

Array.last

pub pure noalloc fn Array[T: Copy].last(self) -> T?

The last element, or None when the array is empty.

Array.isEmpty

pub pure noalloc fn Array[T].isEmpty(self) -> Bool

Whether the array has no elements.

Array.slice

pub pure fn Array[T: Copy].slice(self, start: usize, end: usize) -> Array[T]?

Copies of self[start..end]; None unless start <= end <= self.len().

Array.trySlice

pub pure fn Array[T: Copy].trySlice(self, start: usize, end: usize) -> Result[Array[T]?, AllocError]

Copies of self[start..end]; Ok(None) unless start <= end <= self.len(), AllocError when the allocator refuses (slice panics instead).

Array.concat

pub pure fn Array[T: Copy].concat(self, other: Array[T]) -> Array[T]

New array holding the elements of self followed by those of other.

Array.tryConcat

pub pure fn Array[T: Copy].tryConcat(self, other: Array[T]) -> Result[Array[T], AllocError]

New array holding the elements of self followed by those of other, or AllocError when the allocator refuses (concat panics instead).

Functions

sortedBy

pub pure fn sortedBy[T: Copy](items: &Array[T], order: fn(&T, &T) -> Ordering) -> Array[T]

Sorted copy of items; order decides which of two elements comes first.

trySortedBy

pub pure fn trySortedBy[T: Copy](items: &Array[T], order: fn(&T, &T) -> Ordering) -> Result[Array[T], AllocError]

Same as sortedBy, or AllocError when the allocator refuses (sortedBy panics instead).

join

pub pure fn join(items: &Array[String], sep: String) -> String

Concatenates items with sep between consecutive elements.

tryJoin

pub pure fn tryJoin(items: &Array[String], sep: String) -> Result[String, AllocError]

Same as join, or AllocError when the allocator refuses (join panics instead).