[−][src]Struct gen_vec::exposed::gen_vec::ExposedGenVec
Generationally indexed vector that relies on an independent IndexAllocator
Implementations
impl<T> ExposedGenVec<T>
[src]
pub fn new() -> ExposedGenVec<T>
[src]
Returns an empty ExposedGenVec
Examples
use gen_vec::exposed::ExposedGenVec; let mut vec: ExposedGenVec<i32> = ExposedGenVec::new();
pub fn with_capacity(capacity: usize) -> ExposedGenVec<T>
[src]
Returns a ExposedGenVec
with initial capacity of capacity
Allows the ExposedGenVec
to hold capacity
elements before
allocating more space
Examples
use gen_vec::exposed::ExposedGenVec; let mut vec: ExposedGenVec<i32> = ExposedGenVec::with_capacity(5);
pub fn capacity(&self) -> usize
[src]
Reserved capacity within the ExposedGenVec
Examples
use gen_vec::exposed::ExposedGenVec; let mut vec: ExposedGenVec<i32> = ExposedGenVec::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::exposed::{IndexAllocator, ExposedGenVec}; let mut allocator: IndexAllocator = IndexAllocator::new(); let index: Index = allocator.allocate(); let mut vec: ExposedGenVec<i32> = ExposedGenVec::new(); assert_eq!(vec.capacity(), 0); vec.set(index, 0); vec.reserve(4); assert!(vec.capacity() >= 4);
pub fn contains(&self, index: Index) -> bool
[src]
Returns true
if the index
points to a valid item
Examples
use gen_vec::Index; use gen_vec::exposed::{IndexAllocator, ExposedGenVec}; let mut allocator: IndexAllocator = IndexAllocator::new(); let index: Index = allocator.allocate(); let mut vec: ExposedGenVec<i32> = ExposedGenVec::new(); assert!(!vec.contains(index)); vec.set(index, 0); assert!(vec.contains(index));
pub fn set(&mut self, index: Index, value: T) -> Option<T>
[src]
Set the value for the given index
and returns the previous value (if any)
This may overwrite past (but not future) generations
Examples
use gen_vec::Index; use gen_vec::exposed::{IndexAllocator, ExposedGenVec}; let mut allocator: IndexAllocator = IndexAllocator::new(); let index: Index = allocator.allocate(); let mut vec: ExposedGenVec<i32> = ExposedGenVec::new(); vec.set(index, 0); assert!(vec.contains(index)); let replaced: i32 = vec.set(index, 1).expect("0"); assert_eq!(replaced, 0);
pub fn remove(&mut self, index: Index) -> Option<T>
[src]
Removes the value of index
from the vec and internally sets the element to None
Examples
use gen_vec::exposed::{IndexAllocator, ExposedGenVec}; let mut allocater: IndexAllocator = IndexAllocator::new(); let index = allocater.allocate(); let mut vec: ExposedGenVec<i32> = ExposedGenVec::new(); vec.set(index, 0); let replaced: Option<i32> = vec.set(index, 1); assert_eq!(replaced, Some(0));
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::exposed::{IndexAllocator, ExposedGenVec}; let mut allocator: IndexAllocator = IndexAllocator::new(); let index: Index = allocator.allocate(); let mut vec: ExposedGenVec<i32> = ExposedGenVec::new(); vec.set(index, 0); let value: Option<&i32> = vec.get(index); assert_eq!(value, Some(&0));
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::exposed::{IndexAllocator, ExposedGenVec}; let mut allocator: IndexAllocator = IndexAllocator::new(); let index: Index = allocator.allocate(); let mut vec: ExposedGenVec<i32> = ExposedGenVec::new(); vec.set(index, 0); let mut value: Option<&mut i32> = vec.get_mut(index); assert_eq!(value, Some(&mut 0)); if let Some(value) = value { *value = 1; } let value: Option<&i32> = vec.get(index); assert_eq!(value, Some(&1));
pub fn iter(&self) -> Iter<T>ⓘ
[src]
Returns an iterator of immutable references to the vec elements
Each iterator step returns (Index, &T)
Examples
use gen_vec::Index; use gen_vec::exposed::{IndexAllocator, ExposedGenVec}; let mut allocator: IndexAllocator = IndexAllocator::new(); let mut vec: ExposedGenVec<i32> = ExposedGenVec::new(); vec.set(allocator.allocate(), 0); vec.set(allocator.allocate(), 1); for (index, value) in vec.iter() { println!("Index: {:?}, Value: {}", index, value); } // This works as well for (index, value) in vec { println!("Index: {:?}, Value: {}", index, value); }
pub fn iter_mut(&mut self) -> IterMut<T>ⓘ
[src]
Returns an iterator of mutable references to the vec elements
Each iterator step returns (Index, &mut T)
Examples
use gen_vec::Index; use gen_vec::exposed::{IndexAllocator, ExposedGenVec}; let mut allocator: IndexAllocator = IndexAllocator::new(); let mut vec: ExposedGenVec<i32> = ExposedGenVec::new(); vec.set(allocator.allocate(), 0); vec.set(allocator.allocate(), 1); for (index, value) in vec.iter_mut() { *value = 30; }
Trait Implementations
impl<T: Debug> Debug for ExposedGenVec<T>
[src]
impl<T: Default> Default for ExposedGenVec<T>
[src]
fn default() -> ExposedGenVec<T>
[src]
impl<T> Index<Index> for ExposedGenVec<T>
[src]
type Output = T
The returned type after indexing.
fn index(&self, index: Index) -> &Self::Output
[src]
impl<T> IndexMut<Index> for ExposedGenVec<T>
[src]
impl<T> IntoIterator for ExposedGenVec<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?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, T> IntoIterator for &'a ExposedGenVec<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?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, T> IntoIterator for &'a mut ExposedGenVec<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for ExposedGenVec<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for ExposedGenVec<T> where
T: Send,
T: Send,
impl<T> Sync for ExposedGenVec<T> where
T: Sync,
T: Sync,
impl<T> Unpin for ExposedGenVec<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for ExposedGenVec<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
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> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
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?
fn into_iter(self) -> I
[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>,