Struct VecStorage

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

Re-usable memory for creating a vector of references.

See the module-level documentation for more information.

Implementations§

Source§

impl<T> VecStorage<T>

Source

pub fn with_capacity(capacity: usize) -> Self

Create a new VecStorage<T> with the provided capacity.

§Example
use vecstorage::VecStorage;

let storage = VecStorage::<u32>::with_capacity(5);
assert_eq!(storage.capacity(), 5);
Source

pub fn capacity(&self) -> usize

Get the capacity of the VecStorage.

§Example
use vecstorage::VecStorage;

let storage = VecStorage::<u32>::with_capacity(5);
assert_eq!(storage.capacity(), 5);
Source

pub fn vec_guard<'s, TGuard>(&'s mut self) -> VecGuard<'s, T, TGuard>

Creates a new VecGuard using the memory allocated by self. This VecGuard` will automatically clear the vector when it goes out of scope.

§Panics

Panics if TGuard doesn’t have the same size and alignment as T.

Panics if mem::forget() was called on a VecGuard that was created previously on the same VecStorage.

§Example
use vecstorage::VecStorage;

let mut storage = VecStorage::<u32>::with_capacity(2);
{
   let mut guard = storage.vec_guard();
   assert_eq!(guard.capacity(), 2);
   assert_eq!(guard.len(), 0);
   guard.push(3);
   guard.push(2);
}
{
   let mut guard = storage.vec_guard::<u32>();
   assert_eq!(guard.capacity(), 2); // The memory of the `storage` is reused
   assert_eq!(guard.len(), 0);      // But its contents has been "cleared".
}

Trait Implementations§

Source§

impl<T: Debug> Debug for VecStorage<T>

Source§

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

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

impl<T> Drop for VecStorage<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> Send for VecStorage<T>
where T: Send,

Source§

impl<T> Sync for VecStorage<T>
where T: Sync,

Auto Trait Implementations§

§

impl<T> Freeze for VecStorage<T>

§

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

§

impl<T> Unpin for VecStorage<T>
where T: Unpin,

§

impl<T> UnwindSafe for VecStorage<T>
where 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.