[][src]Struct gen_vec::closed::ClosedGenVec

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

Generationally indexed vector with an internal index allocator

Implementations

impl<T> ClosedGenVec<T>[src]

pub fn new() -> ClosedGenVec<T>[src]

Returns an empty ClosedGenVec

Examples

use gen_vec::closed::ClosedGenVec;
let mut vec: ClosedGenVec<i32> = ClosedGenVec::new();

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

Returns a ClosedGenVec with initial capacity of capacity

Allows the ClosedGenVec to hold capacity elements before allocating more space

Examples

use gen_vec::closed::ClosedGenVec;
let mut vec: ClosedGenVec<i32> = ClosedGenVec::with_capacity(5);

pub fn len(&self) -> usize[src]

Number of active Items within the vec

The internal item vec may actually be larger depending on the number of freed indices

Examples

use gen_vec::Index;
use gen_vec::closed::ClosedGenVec;

let mut vec: ClosedGenVec<i32> = ClosedGenVec::new();

let index: Index = vec.insert(42);
assert_eq!(vec.len(), 1);

vec.remove(index);
assert_eq!(vec.len(), 0);

pub fn is_empty(&self) -> bool[src]

Returns true if there are no active items

Examples

use gen_vec::Index;
use gen_vec::closed::ClosedGenVec;

let mut vec: ClosedGenVec<i32> = ClosedGenVec::new();
assert!(vec.is_empty());

let index: Index = vec.insert(23);
assert!(!vec.is_empty());

vec.remove(index);
assert!(vec.is_empty());

pub fn capacity(&self) -> usize[src]

Reserved capacity within the vec

Examples

use gen_vec::closed::ClosedGenVec;

let mut vec: ClosedGenVec<i32> = ClosedGenVec::with_capacity(5);
assert_eq!(vec.capacity(), 5);

pub fn reserve(&mut self, additional: usize)[src]

Reserves extra space for at least additional more elements

More space may be allocated to avoid frequent re-allocations (as per the specifications of std::vec::Vec)

Examples

use gen_vec::Index;
use gen_vec::closed::ClosedGenVec;

let mut vec: ClosedGenVec<i32> = ClosedGenVec::new();
assert_eq!(vec.capacity(), 0);

let index: Index = vec.insert(13);

vec.reserve(4);
assert!(vec.capacity() >= 4)

pub fn insert(&mut self, value: T) -> Index[src]

Insert value and return an associated Index

Examples

use gen_vec::Index;
use gen_vec::closed::ClosedGenVec;
let mut vec: ClosedGenVec<i32> = ClosedGenVec::new();

let index: Index = vec.insert(23);

pub fn contains(&self, index: Index) -> bool[src]

Returns true if the index points to a valid item within

Examples

use gen_vec::Index;
use gen_vec::closed::ClosedGenVec;

let mut vec: ClosedGenVec<i32> = ClosedGenVec::new();

let index: Index = vec.insert(124);
assert!(vec.contains(index));

vec.remove(index);
assert!(!vec.contains(index));

pub fn remove(&mut self, index: Index) -> Option<T>[src]

Returns the value of index if index is valid

Afterwards, index is added to the pool of free indices available for reuse

Examples

use gen_vec::Index;
use gen_vec::closed::ClosedGenVec;

let mut vec: ClosedGenVec<i32> = ClosedGenVec::new();

let index: Index = vec.insert(124);
assert!(vec.contains(index));

vec.remove(index);
assert!(!vec.contains(index));

pub fn clear(&mut self)[src]

Free all items

Internal capacity will not change. Internally this is performed as all Some(_) being replaced with None

Examples

use gen_vec::Index;
use gen_vec::closed::ClosedGenVec;

let mut vec: ClosedGenVec<i32> = ClosedGenVec::new();

let index: Index = vec.insert(42);
assert!(vec.contains(index));

vec.clear();

assert!(!vec.contains(index));

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

Returns an immutable reference to the value of index if index is valid

Examples

use gen_vec::Index;
use gen_vec::closed::ClosedGenVec;
let mut vec: ClosedGenVec<i32> = ClosedGenVec::new();

let index: Index = vec.insert(23);

let value: Option<&i32> = vec.get(index);
assert_eq!(value, Some(&23));

pub fn get_mut(&mut self, index: Index) -> Option<&mut T>[src]

Returns a mutable reference to the value of index if index is valid

Examples

use gen_vec::Index;
use gen_vec::closed::ClosedGenVec;
let mut vec: ClosedGenVec<i32> = ClosedGenVec::new();

let index: Index = vec.insert(23);

let mut value: Option<&mut i32> = vec.get_mut(index);
assert_eq!(value, Some(&mut 23));

if let Some(value) = value
{
    *value = 0;
}

let value: Option<&i32> = vec.get(index);
assert_eq!(value, Some(&0));

pub fn iter(&self) -> Iter<T>

Important traits for Iter<'a, T>

impl<'a, T> Iterator for Iter<'a, T> type Item = (Index, &'a T);
[src]

Returns an iterator of immutable references to the vec elements

Each iterator step returns (Index, &T)

Examples

use gen_vec::closed::ClosedGenVec;

let mut vec: ClosedGenVec<i32> = ClosedGenVec::new();
vec.insert(0);
vec.insert(1);

for (index, value) in vec // vec.iter() is valid too
{
    println!("Index: {:?}, Value: {}", index, value);
}

pub fn iter_mut(&mut self) -> IterMut<T>

Important traits for IterMut<'a, T>

impl<'a, T: 'a> Iterator for IterMut<'a, T> type Item = (Index, &'a mut T);
[src]

Returns an iterator of mutable references to the vec elements

Each iterator step returns (Index, &mut T)

Examples

use gen_vec::closed::ClosedGenVec;

let mut vec: ClosedGenVec<i32> = ClosedGenVec::new();
vec.insert(0);
vec.insert(1);

for (index, value) in vec.iter_mut()
{
    *value = 0;
}

Trait Implementations

impl<T: Debug> Debug for ClosedGenVec<T>[src]

impl<T: Default> Default for ClosedGenVec<T>[src]

impl<T> Index<Index> for ClosedGenVec<T>[src]

type Output = T

The returned type after indexing.

impl<T> IndexMut<Index> for ClosedGenVec<T>[src]

impl<T> IntoIterator for ClosedGenVec<T>[src]

type Item = (Index, T)

The type of the elements being iterated over.

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?

impl<'a, T> IntoIterator for &'a ClosedGenVec<T>[src]

type Item = (Index, &'a T)

The type of the elements being iterated over.

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?

impl<'a, T> IntoIterator for &'a mut ClosedGenVec<T>[src]

type Item = (Index, &'a mut T)

The type of the elements being iterated over.

type IntoIter = IterMut<'a, T>

Which kind of iterator are we turning this into?

Auto Trait Implementations

impl<T> RefUnwindSafe for ClosedGenVec<T> where
    T: RefUnwindSafe

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

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

impl<T> Unpin for ClosedGenVec<T> where
    T: Unpin

impl<T> UnwindSafe for ClosedGenVec<T> where
    T: UnwindSafe

Blanket Implementations

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

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

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

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

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

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

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.