v0.4.0

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) -> 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) -> bool

Whether the elements are still inline, with nothing allocated.

Returns: whether it is inline

Source

Length

pub func Length(&self) -> uint

How many elements it holds.

Returns: the count

Source

IsEmpty

pub func IsEmpty(&self) -> bool

Whether it holds nothing.

Returns: whether it is empty

Source

Capacity

pub func Capacity(&self) -> uint

How many elements fit before the next allocation.

Returns: the capacity

Source

Push

pub func Push(&var self, value: T)

Appends value, moving it in, and allocating only once the inline room is full. Terminates the program when the storage cannot grow.

NameTypeDescription
valueTthe element

Source

Pop

pub func Pop(&var self) -> T?

Takes the last element out, moving it rather than copying it.

Returns: the element, or none when the vector is empty

Source

Get

pub func Get(&self, 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) -> T[..]

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

Returns: a view of them

Source

AsMutableSlice

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

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

Returns: a view of them

Source

Truncate

pub func Truncate(&var self, length: uint)

Destroys the elements past length, keeping the storage.

NameTypeDescription
lengthuinthow many to keep

Source

Clear

pub func Clear(&var self)

Destroys every element, keeping the storage.

Source

Destructor

func ~SmallVector(&var self)

Source