[−][src]Struct gvec::GenerationalVec
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,
T: Send,
impl<T> Sync for GenerationalVec<T> where
T: Sync,
T: Sync,
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)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> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,