pub struct Vec<T: Storable, M: Memory>(/* private fields */);Expand description
An implementation of growable arrays in stable memory.
Implementations§
Source§impl<T: Storable, M: Memory> Vec<T, M>
impl<T: Storable, M: Memory> Vec<T, M>
Sourcepub fn new(memory: M) -> Self
pub fn new(memory: M) -> Self
Creates a new empty vector in the specified memory, overwriting any data structures the memory might have contained previously.
Complexity: O(1)
Sourcepub fn init(memory: M) -> Self
pub fn init(memory: M) -> Self
Initializes a vector in the specified memory.
Complexity: O(1)
PRECONDITION: the memory is either empty or contains a valid stable vector.
Sourcepub fn into_memory(self) -> M
pub fn into_memory(self) -> M
Returns the underlying memory instance.
Sourcepub fn set(&self, index: u64, item: &T)
pub fn set(&self, index: u64, item: &T)
Sets the item at the specified index to the specified value.
Complexity: O(max_size(T))
PRECONDITION: index < self.len()
Sourcepub fn get(&self, index: u64) -> Option<T>
pub fn get(&self, index: u64) -> Option<T>
Returns the item at the specified index.
Complexity: O(max_size(T))
Sourcepub fn push(&self, item: &T)
pub fn push(&self, item: &T)
Adds a new item at the end of the vector.
Complexity: O(max_size(T))
Sourcepub fn pop(&self) -> Option<T>
pub fn pop(&self) -> Option<T>
Removes the item at the end of the vector.
Complexity: O(max_size(T))
pub fn iter(&self) -> impl DoubleEndedIterator<Item = T> + '_
Trait Implementations§
Auto Trait Implementations§
impl<T, M> Freeze for Vec<T, M>where
M: Freeze,
impl<T, M> RefUnwindSafe for Vec<T, M>where
M: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, M> Send for Vec<T, M>
impl<T, M> Sync for Vec<T, M>
impl<T, M> Unpin for Vec<T, M>
impl<T, M> UnwindSafe for Vec<T, M>where
M: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more