pub struct SmallVec<T, const N: usize> where
    T: PackedLayout
{ /* private fields */ }
Expand description

A contiguous growable array type.

Note

  • The storage::SmallVec has a very similar API compared to a storage::Vec. The major difference between both data structures is that the SmallVec can only contain up to a fixed amount of elements given by N whereas the Vec can contain up to 2^32 elements which is the maximum for 32-bit Wasm targets.
  • The performance characteristics may be different from Rust’s Vec due to the internal differences.
  • Allows to store up to N elements.

Implementations

Creates a new empty vector.

Returns the capacity of the small vector.

Returns the number of elements in the vector, also referred to as its length.

Returns true if the vector contains no elements.

Returns an iterator yielding shared references to all elements.

Note
  • Avoid unbounded iteration over big storage vectors.
  • Prefer using methods like Iterator::take in order to limit the number of yielded elements.

Returns an iterator yielding exclusive references to all elements.

Note
  • Avoid unbounded iteration over big storage vectors.
  • Prefer using methods like Iterator::take in order to limit the number of yielded elements.

Returns a shared reference to the first element if any.

Returns a shared reference to the last element if any.

Returns a shared reference to the indexed element.

Returns None if index is out of bounds.

Appends an element to the back of the vector.

Pops the last element from the vector and returns it. Returns None if the vector is empty.

Pops the last element from the vector and immediately drops it.

Returns Some(()) if an element has been removed and None otherwise.

Note

This operation is a bit more efficient than SmallVec::pop since it avoids reading from contract storage in some use cases.

Returns an exclusive reference to the first element if any.

Returns an exclusive reference to the last element if any.

Returns an exclusive reference to the indexed element.

Returns None if index is out of bounds.

Swaps the elements at the given indices.

Panics

If one or both indices are out of bounds.

Removes the indexed element from the vector and returns it.

The last element of the vector is put into the indexed slot. Returns None and does not mutate the vector if the index is out of bounds.

Note

This operation does not preserve ordering but is constant time.

Removes the indexed element from the vector.

The last element of the vector is put into the indexed slot. Returns Some(()) if an element has been removed and None otherwise.

Note

This operation should be preferred over Vec::swap_remove if there is no need to return the removed element since it avoids a contract storage read for some use cases.

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Executes the destructor for this type. Read more

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Creates a value from an iterator. Read more

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

Performs the mutable indexing (container[index]) operation. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Default initializes the implementing type using spread layout. Read more

The footprint of the type. Read more

Pulls an instance of Self from the contract storage. Read more

Pushes an instance of Self to the contract storage. Read more

Clears an instance of Self from the contract storage. Read more

Indicates whether a type requires deep clean-up of its state meaning that a clean-up routine has to decode an entity into an instance in order to eventually recurse upon its tear-down. This is not required for the majority of primitive data types such as i32, however types such as storage::Box that might want to forward the clean-up procedure to their inner T require a deep clean-up. Read more

Returns the static storage layout of Self. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.