[][src]Struct near_sdk::collections::Vector

pub struct Vector<T> { /* fields omitted */ }

An iterable implementation of vector that stores its content on the trie. Uses the following map: index -> element.

Implementations

impl<T> Vector<T>[src]

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

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

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

Returns true if the vector contains no elements.

pub fn new(id: Vec<u8>) -> Self[src]

Create new vector with zero elements. Use id as a unique identifier on the trie.

pub fn get_raw(&self, index: u64) -> Option<Vec<u8>>[src]

Returns the serialized element by index or None if it is not present.

pub fn swap_remove_raw(&mut self, index: u64) -> Vec<u8>[src]

Removes an element from the vector and returns it in serialized form. The removed element is replaced by the last element of the vector. Does not preserve ordering, but is O(1).

Panics

Panics if index is out of bounds.

pub fn push_raw(&mut self, raw_element: &[u8])[src]

Appends a serialized element to the back of the collection.

pub fn pop_raw(&mut self) -> Option<Vec<u8>>[src]

Removes the last element from a vector and returns it without deserializing, or None if it is empty.

pub fn replace_raw(&mut self, index: u64, raw_element: &[u8]) -> Vec<u8>[src]

Inserts a serialized element at index, returns a serialized evicted element.

Panics

If index is out of bounds.

pub fn iter_raw<'a>(&'a self) -> impl Iterator<Item = Vec<u8>> + 'a[src]

Iterate over raw serialized elements.

pub fn extend_raw<IT: IntoIterator<Item = Vec<u8>>>(&mut self, iter: IT)[src]

Extends vector from the given collection of serialized elements.

impl<T> Vector<T>[src]

pub fn clear(&mut self)[src]

Removes all elements from the collection.

impl<T> Vector<T> where
    T: BorshSerialize
[src]

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

Appends an element to the back of the collection.

pub fn extend<IT: IntoIterator<Item = T>>(&mut self, iter: IT)[src]

Extends vector from the given collection.

impl<T> Vector<T> where
    T: BorshDeserialize
[src]

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

Returns the element by index or None if it is not present.

pub fn swap_remove(&mut self, index: u64) -> T[src]

Removes an element from the vector and returns it. The removed element is replaced by the last element of the vector. Does not preserve ordering, but is O(1).

Panics

Panics if index is out of bounds.

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

Removes the last element from a vector and returns it, or None if it is empty.

pub fn iter<'a>(&'a self) -> impl Iterator<Item = T> + 'a[src]

Iterate over deserialized elements.

pub fn to_vec(&self) -> Vec<T>[src]

impl<T> Vector<T> where
    T: BorshSerialize + BorshDeserialize
[src]

pub fn replace(&mut self, index: u64, element: &T) -> T[src]

Inserts a element at index, returns an evicted element.

Panics

If index is out of bounds.

Trait Implementations

impl<T> BorshDeserialize for Vector<T> where
    u64: BorshDeserialize,
    Vec<u8>: BorshDeserialize
[src]

impl<T> BorshSerialize for Vector<T> where
    u64: BorshSerialize,
    Vec<u8>: BorshSerialize
[src]

impl<T: Debug> Debug for Vector<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for Vector<T> where
    T: RefUnwindSafe
[src]

impl<T> Send for Vector<T> where
    T: Send
[src]

impl<T> Sync for Vector<T> where
    T: Sync
[src]

impl<T> Unpin for Vector<T> where
    T: Unpin
[src]

impl<T> UnwindSafe for Vector<T> where
    T: UnwindSafe
[src]

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.