pub struct Vector<T> { /* private fields */ }Implementations§
Source§impl<T> Vector<T>where
T: BorshSerialize + BorshDeserialize,
impl<T> Vector<T>where
T: BorshSerialize + BorshDeserialize,
Sourcepub fn new<S: Into<String>>(prefix: S) -> Self
pub fn new<S: Into<String>>(prefix: S) -> Self
Constructs a new, empty Vector<T>.
The vector header will not write itself to the GS, even if values are pushed onto it later.
Sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
Removes the last element from a vector and returns it, or None if it is empty.
Sourcepub fn contains(&self, value: &T) -> boolwhere
T: PartialEq,
pub fn contains(&self, value: &T) -> boolwhere
T: PartialEq,
Returns true if the slice contains an element with the given value.
This operation is O(n).
Sourcepub fn iter(&self) -> impl Iterator<Item = T> + '_
pub fn iter(&self) -> impl Iterator<Item = T> + '_
Returns an iterator over self, with elements deserialized.
Sourcepub fn insert(&mut self, index: u64, value: T)
pub fn insert(&mut self, index: u64, value: T)
Inserts an element at position index within the vector, shifting all elements after it to
the right.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the vector, removing all values from the global state. This is potentially expensive, as it requires an iteration over all elements to remove them from the global state.
Sourcepub fn len(&self) -> u64
pub fn len(&self) -> u64
Returns the number of elements in the vector, also referred to as its ‘length’.
Sourcepub fn binary_search(&self, value: &T) -> Result<u64, u64>where
T: Ord,
pub fn binary_search(&self, value: &T) -> Result<u64, u64>where
T: Ord,
Binary searches this vector for a given element. If the vector is not sorted, the returned result is unspecified and meaningless.
Sourcepub fn binary_search_by<F>(&self, f: F) -> Result<u64, u64>
pub fn binary_search_by<F>(&self, f: F) -> Result<u64, u64>
Binary searches this slice with a comparator function.
The comparator function should return an Ordering that indicates whether its argument is
Less, Equal or Greater the desired target. If the slice is not sorted or if the
comparator function does not implement an order consistent with the sort order of the
underlying slice, the returned result is unspecified and meaningless.
Sourcepub fn remove(&mut self, index: u64) -> Option<T>
pub fn remove(&mut self, index: u64) -> Option<T>
Removes the element at the specified index and returns it.
Note: Because this shifts over the remaining elements, it has a
worst-case performance of O(n). If you don’t need the order of
elements to be preserved, use swap_remove instead.
Sourcepub fn swap_remove(&mut self, index: u64) -> Option<T>
pub fn swap_remove(&mut self, index: u64) -> Option<T>
Removes the element at the specified index and returns it.
The removed element is replaced by the last element of the vector. This does not preserve ordering of the remaining elements, but is O(1).