ui_app

module std::vectorsource

The growable array.

A Vector owns a heap buffer and a count of the elements in use; the slots past them hold moved-from values. Growing allocates a buffer of moved-from values, zero bytes that nothing copies, and moves the elements into it with one range move, which frees the old buffer without visiting its slots (section 5.2). The buffer grows by half on exhaustion, so pushes are amortized constant. An empty vector has no buffer. A vector of disposable elements is disposable itself and disposes them in order (section 5.2).

type Vectorsource

exp type Vector<T> : Iterable<T, VectorCursor<T>> + Disposable if (
    T: Disposable
) + Equal + Format if (T: Format) = struct

Functions

fn formatsource

exp fn format<T: Format>(self vector: &Vector<T>, out: &var String)

Writes the elements as [a, b, c] (std::format).

fn Vector::emptysource

exp fn Vector::empty() -> Vector<T>

A vector with no elements and no allocation.

fn Vector::with_capacitysource

exp fn Vector::with_capacity(capacity: u64) -> Vector<T>

An empty vector with room for capacity elements, so that many pushes allocate nothing more.

fn Vector::fromsource

exp fn Vector::from(items: &[T]) -> Vector<T>

A vector holding copies of the items, allocated to fit them; disposable items cannot be copied, so their vectors are filled by push.

fn Vector::filledsource

exp fn Vector::filled(item: T, count: u64) -> Vector<T>

A vector of count copies of the item, allocated to fit them.

fn disposesource

exp fn dispose<T: Disposable>(self vector: &var Vector<T>)

Disposes the elements in order and empties the vector, freeing its buffer; the elements past the count are moved-from fillers.

fn equalssource

exp fn equals<T>(self vector: &Vector<T>, other: &Vector<T>) -> bool

What == compares: the elements in use, in order, whatever the capacities.

fn lengthsource

exp fn length<T>(self vector: &Vector<T>) -> u64

The number of elements in use.

fn pushsource

exp fn push<T>(self vector: &var Vector<T>, item: T)

Appends one element, growing the buffer when it is full. The elements move (section 5.2), so an owning element keeps its allocation.

fn reservesource

exp fn reserve<T>(self vector: &var Vector<T>, additional: u64)

Makes room for additional more elements, so that many pushes do not grow the buffer again.

fn appendsource

exp fn append<T>(self vector: &var Vector<T>, items: &[T])

Appends copies of the items, growing the buffer at most once: as many pushes, without a check each. Disposable items cannot be copied; push them instead.

fn getsource

exp fn get<T>(self vector: &Vector<T>, index: u64) -> &T

The element at the index, in place; a fault past the end. Like any reference, it is invalidated when a later push grows the buffer.

fn get_varsource

exp fn get_var<T>(self vector: &var Vector<T>, index: u64) -> &var T

The element at the index, in place for writing; a fault past the end.

fn try_getsource

exp fn try_get<T>(self vector: &Vector<T>, index: u64) -> Option<&T>

The element at the index in place, or None past the end.

fn viewsource

exp fn view<T>(self vector: &Vector<T>) -> &[T]

Borrows the elements in use as a &[T] slice, in place. The view is invalidated by the next mutation (growth may reallocate), like any Alloy reference.

fn setsource

exp fn set<T>(self vector: &var Vector<T>, index: u64, item: T)

Overwrites the element at the index, moving the item in; past the end the item is dropped instead. A disposable element replaced, or item dropped, is disposed first, as C++'s assignment releases what it replaces (section 5.2).

fn popsource

exp fn pop<T>(self vector: &var Vector<T>) -> Option<T>

Removes and returns the last element, or None when empty. The element moves out (section 5.2), and the buffer is kept for future pushes.

fn truncatesource

exp fn truncate<T>(self vector: &var Vector<T>, length: u64)

Drops every element past the length, last first, keeping the buffer; a disposable element is disposed first, as C++'s resize destroys what it removes.

fn clearsource

exp fn clear<T>(self vector: &var Vector<T>)

Drops every element, disposing a disposable one first, and keeps the buffer for future pushes.

fn lastsource

exp fn last<T>(self vector: &Vector<T>) -> &T

The last element in place; a fault when the vector is empty.

fn try_lastsource

exp fn try_last<T>(self vector: &Vector<T>) -> Option<&T>

The last element in place, or None when empty.

fn shrinksource

exp fn shrink<T>(self vector: &var Vector<T>)

Gives back the room past the elements in use, moving them into a buffer that holds just them: for a vector done growing and kept.

fn itemssource

exp fn items<T>(self vector: &var Vector<T>) -> &var [T]

Borrows the elements in use mutably, in place, for writing or sorting them; invalidated by the next push like any reference into the vector.

fn replacesource

exp fn replace<T>(self vector: &var Vector<T>, index: u64, item: T) -> T

Puts the item at the index and returns the element it replaces; a fault past the end.

fn try_replacesource

exp fn try_replace<T>(self vector: &var Vector<T>, index: u64, item: T) -> Option<T>

Puts the item at the index and returns the element it replaces, or None past the end, where the item is dropped.

fn removesource

exp fn remove<T>(self vector: &var Vector<T>, index: u64) -> T

Removes and returns the element at the index, the later elements moving down one place, keeping their order; a fault past the end.

fn try_removesource

exp fn try_remove<T>(self vector: &var Vector<T>, index: u64) -> Option<T>

Removes and returns the element at the index, or None past the end; the later elements move down one place, keeping their order.

fn swap_removesource

exp fn swap_remove<T>(self vector: &var Vector<T>, index: u64) -> T

Removes and returns the element at the index in constant time, the last element taking its place; a fault past the end.

fn try_swap_removesource

exp fn try_swap_remove<T>(self vector: &var Vector<T>, index: u64) -> Option<T>

Removes and returns the element at the index, or None past the end, in constant time: the last element takes its place.

fn insertsource

exp fn insert<T>(self vector: &var Vector<T>, index: u64, item: T)

Puts the item at the index, the later elements moving up one place; an index past the end appends it.

fn capacitysource

exp fn capacity<T>(self vector: &Vector<T>) -> u64

The slots the buffer has, in use or not.

type VectorCursorsource

exp type VectorCursor<T> : Iterator<T> = struct

The cursor behind for (vector) |element| (section 5.3): it borrows the vector and hands out references to the elements in place.

Functions

fn iteratorsource

exp fn iterator<T>(self vector: &Vector<T>) -> VectorCursor<T>

fn nextsource

exp fn next<T>(self cursor: &var VectorCursor<T>) -> Option<&T>