SmallVector<T> structv0.1.0
pub struct SmallVector<T> {
// private fields
}
Move-only: it owns its elements.
Type parameters
| Name | Description |
|---|---|
T | the element type |
Constructors
SmallVector
pub func SmallVector(allocator: Allocator) -> SmallVector<T>
An empty vector, holding its first elements inline.
| Name | Type | Description |
|---|---|---|
allocator | Allocator | where the storage comes from once they outgrow it |
Returns: the vector
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
IsInline
pub func IsInline(&self) -> bool
Whether the elements are still inline, with nothing allocated.
Returns: whether it is inline
Length
pub func Length(&self) -> uint
How many elements it holds.
Returns: the count
IsEmpty
pub func IsEmpty(&self) -> bool
Whether it holds nothing.
Returns: whether it is empty
Capacity
pub func Capacity(&self) -> uint
How many elements fit before the next allocation.
Returns: the capacity
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.
| Name | Type | Description |
|---|---|---|
value | T | the element |
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
Get
pub func Get(&self, index: uint) -> T?
A copy of the element at index.
| Name | Type | Description |
|---|---|---|
index | uint | which one |
Returns: the element, or none past the end
AsSlice
pub func AsSlice(&self) -> T[..]
The elements, valid until the vector next changes or moves.
Returns: a view of them
AsMutableSlice
pub func AsMutableSlice(&var self) -> var T[..]
The elements, writable, valid until the vector next changes or moves.
Returns: a view of them
Truncate
pub func Truncate(&var self, length: uint)
Destroys the elements past length, keeping the storage.
| Name | Type | Description |
|---|---|---|
length | uint | how many to keep |
Clear
pub func Clear(&var self)
Destroys every element, keeping the storage.
Destructor
func ~SmallVector(&var self)