SmallVector<T> structv0.1.0

Source
A growable sequence that holds up to 64 bytes of elements without allocating.
pub struct SmallVector<T> {
    // private fields
}

Move-only: it owns its elements.

Type parameters

NameDescription
Tthe element type

Constructors

SmallVector

pub func SmallVector(allocator: Allocator) -> SmallVector<T>

An empty vector, holding its first elements inline.

NameTypeDescription
allocatorAllocatorwhere the storage comes from once they outgrow it

Returns: the vector

Source

Methods

InlineCapacity

pub func InlineCapacity(self: &SmallVector<T>) -> uint

How many elements fit inline: 64 bytes' worth, or none for an element larger than that or aligned to more than eight.

Returns: the inline capacity

Source

IsInline

pub func IsInline(self: &SmallVector<T>) -> bool

Whether the elements are still inline, with nothing allocated.

Returns: whether it is inline

Source

Length

pub func Length(self: &SmallVector<T>) -> uint

How many elements it holds.

Returns: the count

Source

IsEmpty

pub func IsEmpty(self: &SmallVector<T>) -> bool

Whether it holds nothing.

Returns: whether it is empty

Source

Capacity

pub func Capacity(self: &SmallVector<T>) -> uint

How many elements fit before the next allocation.

Returns: the capacity

Source

Push

pub func Push(
    self: &var SmallVector<T>,
    value: T
) -> ! CollectionError

Appends value, moving it in, and allocating only once the inline room is full.

NameTypeDescription
valueTthe element

Returns: nothing, or why there was no room; the vector is unchanged on failure

Source

TryPop

pub func TryPop(
    self: &var SmallVector<T>,
    value: *var T
) -> bool

Takes the last element out.

NameTypeDescription
value*var Treceives the element

Returns: whether there was one

Source

Get

pub func Get(self: &SmallVector<T>, index: uint) -> T?

A copy of the element at index.

NameTypeDescription
indexuintwhich one

Returns: the element, or none past the end

Source

AsSlice

pub func AsSlice(self: &SmallVector<T>) -> T[..]

The elements, valid until the vector next changes or moves.

Returns: a view of them

Source

AsMutableSlice

pub func AsMutableSlice(self: &var SmallVector<T>) -> var T[..]

The elements, writable, valid until the vector next changes or moves.

Returns: a view of them

Source

Truncate

pub func Truncate(self: &var SmallVector<T>, length: uint)

Destroys the elements past length, keeping the storage.

NameTypeDescription
lengthuinthow many to keep

Source

Clear

pub func Clear(self: &var SmallVector<T>)

Destroys every element, keeping the storage.

Source

Destructor

func ~SmallVector(self: &var SmallVector<T>)

Source