#vec #utility #vector

yanked push-vec

A push-only vector type - for getting references to elements and pushing at simultaneously

1.0.0 Apr 12, 2022

#361 in #vec

MIT license

11KB
146 lines

push-vec

A crate that exposes a push-only vector type. Useful for getting a reference to an element and pushing more elements simultaneously


lib.rs:

Provides the PushVec<T> type, which is a vector that cannot be popped from.

This is useful for when you want to continue using a vector while keeping references to its contents.

Example

use push_vec::prelude::*;
let mut vec = push_vec![];
let x: &mut i32 = vec.push(1);
// We are holding a reference to an element, but we can still use the vector.
vec.push(2);
*x = 3;
assert_eq!(vec.into_vec(), vec![3, 2]);

Dependencies

~160KB