[−][src]Struct ink_storage::Vec
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]
T: PackedLayout,
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]
T: PackedLayout,
pub fn iter(&self) -> Iter<'_, 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>ⓘ
[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]
T: PackedLayout,
impl<T> Vec<T> where
T: PackedLayout,
[src]
T: PackedLayout,
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]
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]
T: PackedLayout,
impl<T> Default for Vec<T> where
T: PackedLayout,
[src]
T: PackedLayout,
impl<T> Drop for StorageVec<T> where
T: PackedLayout,
[src]
T: PackedLayout,
impl<T> Eq for StorageVec<T> where
T: Eq + PackedLayout,
[src]
T: Eq + PackedLayout,
impl<T> Extend<T> for StorageVec<T> where
T: PackedLayout,
[src]
T: PackedLayout,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = T>,
[src]
I: IntoIterator<Item = T>,
fn extend_one(&mut self, item: A)
[src]
fn extend_reserve(&mut self, additional: usize)
[src]
impl<T> FromIterator<T> for StorageVec<T> where
T: PackedLayout,
[src]
T: PackedLayout,
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = T>,
[src]
I: IntoIterator<Item = T>,
impl<T> Index<u32> for StorageVec<T> where
T: PackedLayout,
[src]
T: PackedLayout,
impl<T> IndexMut<u32> for StorageVec<T> where
T: PackedLayout,
[src]
T: PackedLayout,
impl<'a, T: 'a> IntoIterator for &'a StorageVec<T> where
T: PackedLayout,
[src]
T: PackedLayout,
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?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, T: 'a> IntoIterator for &'a mut StorageVec<T> where
T: PackedLayout,
[src]
T: PackedLayout,
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?
fn into_iter(self) -> Self::IntoIter
[src]
impl<T> PartialEq<Vec<T>> for StorageVec<T> where
T: PartialEq + PackedLayout,
[src]
T: PartialEq + PackedLayout,
impl<T> SpreadLayout for StorageVec<T> where
T: PackedLayout,
[src]
T: PackedLayout,
const FOOTPRINT: u64
[src]
fn pull_spread(ptr: &mut KeyPtr) -> Self
[src]
fn push_spread(&self, ptr: &mut KeyPtr)
[src]
fn clear_spread(&self, ptr: &mut KeyPtr)
[src]
const REQUIRES_DEEP_CLEAN_UP: bool
[src]
impl<T> StorageLayout for StorageVec<T> where
T: PackedLayout + TypeInfo + 'static,
[src]
T: PackedLayout + TypeInfo + 'static,
Auto Trait Implementations
impl<T> !RefUnwindSafe for Vec<T>
impl<T> Send for Vec<T> where
T: Send,
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,