Struct Persist

Source
pub struct Persist<T> { /* private fields */ }
Expand description

Iteration will not always be in order

Implementations§

Source§

impl<T> Persist<T>

Source

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

Source

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

Source

pub fn from(slice: &[T]) -> Persist<T>
where T: Clone,

Source

pub fn len(&self) -> usize

Returns the actual used length regardless of capacity

Source

pub fn is_empty(&self) -> bool

Source

pub fn capacity(&self) -> usize

Returns the storage capacity

Source

pub fn clear(&mut self)

Clear the storage out while keeping allocated memory

Should not ever panic

Source

pub fn get(&self, index: usize) -> Option<&T>

Source

pub fn get_mut(&mut self, index: usize) -> Option<&mut T>

Source

pub fn is_index_live(&self, index: usize) -> bool

Check if there is a value at this index

Source

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

Source

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

Source

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

Pop the last value in the Persist

Source

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.

Source

pub fn iter(&self) -> Iter<'_, T>

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Trait Implementations§

Source§

impl<T: Debug> Debug for Persist<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Clone> From<&[T]> for Persist<T>

Total capacity will be set from the length of the slice

Source§

fn from(s: &[T]) -> Persist<T>

Converts to this type from the input type.
Source§

impl<T: Clone> From<&mut [T]> for Persist<T>

Total capacity will be set from the length of the slice

Source§

fn from(s: &mut [T]) -> Persist<T>

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T> Freeze for Persist<T>

§

impl<T> RefUnwindSafe for Persist<T>
where T: RefUnwindSafe,

§

impl<T> !Send for Persist<T>

§

impl<T> !Sync for Persist<T>

§

impl<T> !Unpin for Persist<T>

§

impl<T> UnwindSafe for Persist<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.