MemoryStorage

Struct MemoryStorage 

Source
pub struct MemoryStorage<T, U>
where U: AsRef<[Slot<T>]> + AsMut<[Slot<T>]>,
{ /* private fields */ }
Expand description

The instance that will store all the items.

Implementations§

Source§

impl<T> MemoryStorage<T, SlotVec<T>>

Source

pub fn push(&mut self, item: T) -> Id

Push an item ignoring capacity limits. Once the max capacity has been reached the vec simply allocates more space.

Source§

impl<T, U> MemoryStorage<T, U>
where U: AsRef<[Slot<T>]> + AsMut<[Slot<T>]>,

Source

pub fn clear(&mut self)

Clears the storage by turning taken slots into free slots.

Source

pub fn insert(&mut self, item: T) -> Result<Id, InternalStorageFullError<T>>

Try to insert an item. Returning the ID on a successful insert and returning the item wrapped in an error whenever there’s no space left.

Source

pub fn remove(&mut self, id: Id) -> T

Removes an item without shifting the items after it to the left and without invalidating their IDs.

Source

pub fn get(&self, id: Id) -> Option<&T>

Returns a reference to an item whenever it is present.

Source

pub fn get_mut(&mut self, id: Id) -> Option<&mut T>

Returns a mutable reference to an item whenever it is present.

Source

pub fn capacity(&self) -> usize

Returns the current capacity.

Source

pub fn taken_slots(&self) -> usize

Returns how many slots are currently in use.

Source

pub fn storage_ref(&self) -> &U

Acquire a reference to the storage.

Source

pub fn storage(self) -> U

Destroy the instance and acquire the storage.

Auto Trait Implementations§

§

impl<T, U> Freeze for MemoryStorage<T, U>
where U: Freeze,

§

impl<T, U> RefUnwindSafe for MemoryStorage<T, U>

§

impl<T, U> Send for MemoryStorage<T, U>
where U: Send, T: Send,

§

impl<T, U> Sync for MemoryStorage<T, U>
where U: Sync, T: Sync,

§

impl<T, U> Unpin for MemoryStorage<T, U>
where U: Unpin, T: Unpin,

§

impl<T, U> UnwindSafe for MemoryStorage<T, U>
where U: UnwindSafe, T: UnwindSafe,

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.