[][src]Struct gvec::GenerationalVec

pub struct GenerationalVec<T> { /* fields omitted */ }

Methods

impl<T> GenerationalVec<T>[src]

pub fn with_capacity(capacity: usize) -> GenerationalVec<T>[src]

Create a GenVec with a specific capacity

pub fn get(&self, index: GenerationalIndex) -> Option<&T>[src]

Get a value by an index

Returns the value if both the index and the generation do match. Otherwise returns None. A safe alternative to the index [] operator, which can panic if index out-of-bounds or generation does not match.

pub fn insert(&mut self, value: T) -> Result<GenerationalIndex, Error>[src]

Insert a value on the vector

Returns a GenerationalIndex with the index and the generation in which it was added.

Example

use gvec::GenerationalVec;

let mut example = GenerationalVec::with_capacity(2);
let first = example.insert(2).unwrap();
assert_eq!(example[first], 2);

pub fn remove(&mut self, index: GenerationalIndex) -> Result<(), Error>[src]

Remove a value of the vector by a given index

Upon the removal of the value, the index is liberated for use, in order to reuse the space already allocated, and the generation is upped by one, in order to prevent use-after-free scenarios or "address violation" (access another value allocated in the same space (i.e. same index), but with a different generation)

Example

use gvec::GenerationalVec;

let mut example = GenerationalVec::with_capacity(2);
let first = example.insert(1).unwrap();
let second = example.insert(2).unwrap();
assert_eq!(example[first], 1);
example.remove(first);
assert_eq!(example[first], 1); // produces a panic!

Trait Implementations

impl<T> Index<GenerationalIndex> for GenerationalVec<T>[src]

type Output = T

The returned type after indexing.

fn index(&self, index: GenerationalIndex) -> &Self::Output[src]

Panics

Indexing will panic! when the generation of the given index does not match the generation in the vector. Use GenVec::get() instead as a non-panic version that will return an Option.

Auto Trait Implementations

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

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

Blanket Implementations

impl<T> From for T[src]

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

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.