6.2. Array

Provides mutable array types that store their elements on the heap rather than in registers or the stack.

typeArray

An opaque type of supertype Struct.

fn__@ ( self index )

Implements support for the @ operator. Returns a view reference to the element at index of array self.

inline__as ( cls T )

Implements support for the as operator. Arrays can be cast to Generator, or directly passed to for.

inline__countof ( self )

Implements support for the countof operator. Returns the current number of elements stored in self as a value of usize type.

inline__drop ( self )

Implements support for freeing the array’s memory when it goes out of scope.

inline__imply ( cls T )

Implements support for pointer casts, to pass the array to C functions for example.

inline__typecall ( cls element-type capacity )

Construct a mutable array type of element-type with a variable or fixed maximum capacity.

If capacity is defined, then it specifies the maximum number of array elements permitted. If it is undefined, then an initial capacity of 16 elements is assumed, which is doubled whenever it is exceeded, allowing for an indefinite number of elements.

fnappend ( self value )

Append value as an element to the array self and return a reference to the new element. When the array is of GrowingArray type, this operation will transparently resize the array’s storage.

fnclear ( self )

Clear the array and reset its element count to zero. This will drop all elements that have been previously contained by the array.

inlineemplace-append ( self args... )

Construct a new element with arguments args... directly in a newly assigned slot of array self. When the array is of GrowingArray type, this operation will transparently resize the array’s storage.

inlineemplace-append-many ( self size args... )

Construct a new element with arguments args... directly in a newly assigned slot of array self. When the array is of GrowingArray type, this operation will transparently resize the array’s storage.

fnresize ( self count args... )

Resize the array to the specified count. Items are apppend or removed to meet the desired count.

inlinesort ( self key )

Sort elements of array self from smallest to largest, either using the < operator supplied by the element type, or by using the key supplied by the callable key, which is expected to return a comparable value for each element value supplied.

fnswap ( self a b )

Safely swap the contents of two indices.

typeFixedArray

An opaque type of supertype Array.

fn__repr ( self )

Implements support for the repr operation.

inline__typecall ( cls opts... )
inlinecapacity ( self )

Returns the maximum capacity of array self, which is fixed.

fnreserve ( self count )

Internally used by the type. Ensures that array self can hold at least count elements. A fixed array will raise an assertion when its capacity has been exceeded.

typeGrowingArray

An opaque type of supertype Array.

fn__repr ( self )

Implements support for the repr operation.

inline__typecall ( cls opts... )
inlinecapacity ( self )

Returns the current maximum capacity of array self.

fnreserve ( self count )

Internally used by the type. Ensures that array self can hold at least count elements. A growing array will always attempt to comply.