Struct ic_stable_structures::vec::Vec
source · pub struct Vec<T: BoundedStorable, M: Memory>(_);
Expand description
An implementation of growable arrays in stable memory.
Implementations§
source§impl<T: BoundedStorable, M: Memory> Vec<T, M>
impl<T: BoundedStorable, M: Memory> Vec<T, M>
sourcepub fn new(memory: M) -> Result<Self, GrowFailed>
pub fn new(memory: M) -> Result<Self, GrowFailed>
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) -> Result<Self, InitError>
pub fn init(memory: M) -> Result<Self, InitError>
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(T::MAX_SIZE)
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(T::MAX_SIZE)
sourcepub fn push(&self, item: &T) -> Result<(), GrowFailed>
pub fn push(&self, item: &T) -> Result<(), GrowFailed>
Adds a new item at the end of the vector.
Complexity: O(T::MAX_SIZE)
sourcepub fn pop(&self) -> Option<T>
pub fn pop(&self) -> Option<T>
Removes the item at the end of the vector.
Complexity: O(T::MAX_SIZE)
pub fn iter(&self) -> impl Iterator<Item = T> + '_
Trait Implementations§
Auto Trait Implementations§
impl<T, M> RefUnwindSafe for Vec<T, M>where M: RefUnwindSafe, T: RefUnwindSafe,
impl<T, M> Send for Vec<T, M>where M: Send, T: Send,
impl<T, M> Sync for Vec<T, M>where M: Sync, T: Sync,
impl<T, M> Unpin for Vec<T, M>where M: Unpin, T: Unpin,
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