[−][src]Struct gvec::LightVec
Light version of a Vec with Generational scheme
LightVec is a lighter version of DenseVec, a Vec with a so-called Generational scheme, akin to the idea of versioning the indices to prevent use-after-free scenarions when using a given index.
It is so called a lighter version due to the fact that the allocation of indices, i.e. the process that guarantees that indices are versioned, is placed outside the Vec itself.
Methods
impl<T> LightVec<T>
[src]
pub fn with_capacity(capacity: usize) -> (LightVec<T>, LightVecAllocator)
[src]
Creates a new Vec with the given capacity
Creates a new Vec with the given capacity. It also creates an allocator, that is returned alongside the Vec itself.
pub fn get(
&self,
index: &GenerationalIndex,
allocator: &LightVecAllocator
) -> Option<&T>
[src]
&self,
index: &GenerationalIndex,
allocator: &LightVecAllocator
) -> Option<&T>
Returns a value with the given index
Examples
use gvec::{lvec, LightVec, GenerationalIndex}; let (mut example, mut example_alloc, example_indices) = lvec![3; 1]; assert_eq!(example.get(&example_indices[0], &example_alloc), Some(&1));
pub fn insert(
&mut self,
value: T,
allocator: &mut LightVecAllocator
) -> GenerationalIndex
[src]
&mut self,
value: T,
allocator: &mut LightVecAllocator
) -> GenerationalIndex
Inserts a value on the Vec
If the Vec is full, it will reallocate itself (and the allocator) with the 'loan strategy' set on the allocator. If not altered, default loan strategy is set to 1.
Examples
use gvec::LightVec; let (mut example, mut example_alloc) = LightVec::with_capacity(3); let idx = example.insert(1_f32, &mut example_alloc); assert_eq!(example.get(&idx, &example_alloc), Some(&1_f32));
pub fn remove(
&mut self,
index: GenerationalIndex,
allocator: &mut LightVecAllocator
) -> Result<(), Error>
[src]
&mut self,
index: GenerationalIndex,
allocator: &mut LightVecAllocator
) -> Result<(), Error>
Removes a value of the Vec
Removes a value of the Vec with the given index. Index is checked before removal in order to guarantee that the index version is correct. Otherwise, returns an error.
Examples
use gvec::LightVec; let (mut example, mut example_alloc) = LightVec::with_capacity(3); let idx = example.insert(1, &mut example_alloc); assert_eq!(example.remove(idx, &mut example_alloc), Ok(()));
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,