[][src]Struct ink_storage::Vec

pub struct Vec<T> where
    T: PackedLayout
{ /* fields omitted */ }

A contiguous growable array type, written Vec<T> but pronounced 'vector'.

Note

Despite the similarity to Rust's Vec type this storage Vec has many differences in its internal data layout. While it stores its data in contiguous storage slots this does not mean that the data is actually densely stored in memory.

Also its technical performance characteristics may be different from Rust's Vec due to the differences stated above.

Allows to store up to 2^32 elements and is guaranteed to not reallocate upon pushing new elements to it.

Implementations

impl<T> Vec<T> where
    T: PackedLayout
[src]

pub fn new() -> Self[src]

Creates a new empty storage vector.

pub fn len(&self) -> u32[src]

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

pub fn is_empty(&self) -> bool[src]

Returns true if the vector contains no elements.

impl<T> Vec<T> where
    T: PackedLayout
[src]

pub fn iter(&self) -> Iter<'_, T>

Notable traits for Iter<'a, T>

impl<'a, T> Iterator for Iter<'a, T> where
    T: PackedLayout
type Item = &'a T;
[src]

Returns an iterator yielding shared references to all elements of the vector.

Note

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

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Notable traits for IterMut<'a, T>

impl<'a, T> Iterator for IterMut<'a, T> where
    T: PackedLayout
type Item = &'a mut T;
[src]

Returns an iterator yielding exclusive references to all elements of the vector.

Note

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

pub fn first(&self) -> Option<&T>[src]

Returns a shared reference to the first element if any.

pub fn last(&self) -> Option<&T>[src]

Returns a shared reference to the last element if any.

pub fn get(&self, index: u32) -> Option<&T>[src]

Returns a shared reference to the indexed element.

Returns None if index is out of bounds.

impl<T> Vec<T> where
    T: PackedLayout
[src]

pub fn push(&mut self, value: T)[src]

Appends an element to the back of the vector.

impl<T> Vec<T> where
    T: PackedLayout
[src]

pub fn pop(&mut self) -> Option<T>[src]

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

pub fn pop_drop(&mut self) -> Option<()>[src]

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 Vec::pop since it avoids reading from contract storage in some use cases.

pub fn first_mut(&mut self) -> Option<&mut T>[src]

Returns an exclusive reference to the first element if any.

pub fn last_mut(&mut self) -> Option<&mut T>[src]

Returns an exclusive reference to the last element if any.

pub fn get_mut(&mut self, index: u32) -> Option<&mut T>[src]

Returns an exclusive reference to the indexed element.

Returns None if index is out of bounds.

pub fn swap(&mut self, a: u32, b: u32)[src]

Swaps the elements at the given indices.

Panics

If one or both indices are out of bounds.

pub fn swap_remove(&mut self, n: u32) -> Option<T>[src]

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.

pub fn swap_remove_drop(&mut self, n: u32) -> Option<()>[src]

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.

pub fn set(&mut self, index: u32, new_value: T) -> Result<(), IndexOutOfBounds>[src]

Sets the elements at the given index to the new value.

Won't return the old element back to the caller. Prefer this operation over other method of overriding an element in the storage vector since this is more efficient.

pub fn clear(&mut self)[src]

Removes all elements from this vector.

Note

Use this method to clear the vector instead of e.g. iterative pop(). This method performs significantly better and does not actually read any of the elements (whereas pop() does).

Trait Implementations

impl<T: Debug> Debug for Vec<T> where
    T: PackedLayout
[src]

impl<T> Default for Vec<T> where
    T: PackedLayout
[src]

impl<T> Drop for StorageVec<T> where
    T: PackedLayout
[src]

impl<T> Eq for StorageVec<T> where
    T: Eq + PackedLayout
[src]

impl<T> Extend<T> for StorageVec<T> where
    T: PackedLayout
[src]

impl<T> FromIterator<T> for StorageVec<T> where
    T: PackedLayout
[src]

impl<T> Index<u32> for StorageVec<T> where
    T: PackedLayout
[src]

type Output = T

The returned type after indexing.

impl<T> IndexMut<u32> for StorageVec<T> where
    T: PackedLayout
[src]

impl<'a, T: 'a> IntoIterator for &'a StorageVec<T> where
    T: PackedLayout
[src]

type Item = &'a T

The type of the elements being iterated over.

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?

impl<'a, T: 'a> IntoIterator for &'a mut StorageVec<T> where
    T: PackedLayout
[src]

type Item = &'a mut T

The type of the elements being iterated over.

type IntoIter = IterMut<'a, T>

Which kind of iterator are we turning this into?

impl<T> PartialEq<Vec<T>> for StorageVec<T> where
    T: PartialEq + PackedLayout
[src]

impl<T> SpreadLayout for StorageVec<T> where
    T: PackedLayout
[src]

impl<T> StorageLayout for StorageVec<T> where
    T: PackedLayout + TypeInfo + 'static, 
[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for Vec<T>

impl<T> Send for Vec<T> where
    T: Send

impl<T> !Sync for Vec<T>

impl<T> Unpin for Vec<T>

impl<T> !UnwindSafe for Vec<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,