pub struct Persist<T> { /* private fields */ }Expand description
Iteration will not always be in order
Implementations§
Source§impl<T> Persist<T>
impl<T> Persist<T>
Sourcepub fn with_capacity(capacity: usize) -> Persist<T>
pub fn with_capacity(capacity: usize) -> Persist<T>
Allocate with capacity.
This is the only way to create a new persistent vec.
§Panics
Will panic if the selected capacity is larger than the ability for
Persist to internally index in to
Sourcepub fn with_capacity_filled_by<F>(capacity: usize, func: F) -> Persist<T>where
F: Fn() -> T,
pub fn with_capacity_filled_by<F>(capacity: usize, func: F) -> Persist<T>where
F: Fn() -> T,
Allocate with capacity and fill with values produced by a closure
This is a secondary way to create a new persistent vec and is a good way to do so if you know the storage needs to be filled.
§Panics
Will panic if the selected capacity is larger than the ability for
Persist to internally index in to
pub fn from(slice: &[T]) -> Persist<T>where
T: Clone,
pub fn is_empty(&self) -> bool
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clear the storage out while keeping allocated memory
Should not ever panic
pub fn get(&self, index: usize) -> Option<&T>
pub fn get_mut(&mut self, index: usize) -> Option<&mut T>
Sourcepub fn is_index_live(&self, index: usize) -> bool
pub fn is_index_live(&self, index: usize) -> bool
Check if there is a value at this index
Sourcepub fn push(&mut self, value: T) -> Option<usize>
pub fn push(&mut self, value: T) -> Option<usize>
Push T on to storage.
A push is not guaranteed to push in any
particular order if the internal storage has empty locations (typical after
many remove). For this reason it will return the index pushed to.
Returns None if there are no free slots left
Sourcepub fn insert(&mut self, index: usize, value: T) -> Option<T>
pub fn insert(&mut self, index: usize, value: T) -> Option<T>
Insert T at location. Returns existing value in that location or None.
§Panics
Will panic is the index is out of range
Sourcepub fn remove(&mut self, index: usize) -> Option<T>
pub fn remove(&mut self, index: usize) -> Option<T>
Remove the item at this index and return it if it exists. Does not shift elements after it to the left.