Struct VecGrow

Source
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>

Source

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);
Source

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.

Source

pub fn remove(&mut self, index: usize)

Deleting an object and memorize the vacant index.

Source

pub fn count(&self) -> usize

The count of real objects excluding free cells.

Source

pub fn len(&self) -> usize

The length of the object vector

Source

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));
Source

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));
Source

pub fn is_empty(&self) -> bool

Trait Implementations§

Source§

impl<T: Clone> Clone for VecGrow<T>

Source§

fn clone(&self) -> VecGrow<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for VecGrow<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Index<usize> for VecGrow<T>

Source§

type Output = Option<T>

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> IndexMut<usize> for VecGrow<T>

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.