[][src]Struct gvec::LightVec

pub struct LightVec<T>(_);

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]

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]

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]

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

impl<T> Send for LightVec<T> where
    T: Send

impl<T> Sync for LightVec<T> where
    T: Sync

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]