pub struct VecGrow<T> { /* private fields */ }
Expand description
It is similar to a regular Vec
, with one exception -
the size is not reduced. VecGrow
can constantly grow,
but not decrease, and when objects are deleted,
their place remains for the new object as a free index,
which eases the memory power in the case of permanent
deletion and creation of objects.
§Examples
use vector_growing::*;
let mut vg = VecGrow::new();
vg.push(1);
vg.push(2);
assert_eq!(vg[0], Some(1));
assert_eq!(vg[1], Some(2));
vg.remove(0);
assert_eq!(vg[0], None);
vg.push(1);
assert_eq!(vg[0], Some(1));
Initializing VecGrow using a macro:
use vector_growing::*;
let vg_empty: VecGrow<u8> = vec_grow![];
let vg_num = vec_grow![1, 2, 3];
let vg_zero = vec_grow![0; 100];
assert!(vg_empty.is_empty());
assert_eq!(vg_num[1], Some(2));
assert_eq!(vg_zero[99], Some(0));
Implementations§
Source§impl<T> VecGrow<T>
impl<T> VecGrow<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create of VecGrow
§Examples
use vector_growing::*;
let _vg: VecGrow<u8> = VecGrow::new();
// or
let _vg: VecGrow<u8> = vec_grow!();
let _vg = vec_grow!(0);
let _vg = vec_grow!(0; 100);
let _vg = vec_grow!(1, 2, 3);
Sourcepub fn push(&mut self, value: T)
pub fn push(&mut self, value: T)
Adding a new element to the place of the old one, if there is no free space, selected a new place and add the element.
Sourcepub fn iter(&self) -> Iter<'_, T>
pub fn iter(&self) -> Iter<'_, T>
Creating an immutable iterator.
§Examples
use vector_growing::*;
let vg = vec_grow!(1, 2, 3);
let mut vg_iter = vg.iter();
assert_eq!(vg_iter.next(), Some(&1));
assert_eq!(vg_iter.next(), Some(&2));
assert_eq!(vg_iter.next(), Some(&3));
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, T>
pub fn iter_mut(&mut self) -> IterMut<'_, T>
Creating an mutable iterator.
§Examples
use vector_growing::*;
let mut vg = vec_grow!(1, 2, 3);
for num in vg.iter_mut() {
*num += 1;
}
let mut vg_iter = vg.iter();
assert_eq!(vg_iter.next(), Some(&2));
assert_eq!(vg_iter.next(), Some(&3));
assert_eq!(vg_iter.next(), Some(&4));
pub fn is_empty(&self) -> bool
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for VecGrow<T>
impl<T> RefUnwindSafe for VecGrow<T>where
T: RefUnwindSafe,
impl<T> Send for VecGrow<T>where
T: Send,
impl<T> Sync for VecGrow<T>where
T: Sync,
impl<T> Unpin for VecGrow<T>where
T: Unpin,
impl<T> UnwindSafe for VecGrow<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more