Expand description
A non-empty vector type that guarantees at least one element is present. NEVec has an interface similar to Vec with additional methods to enforce the invariant. Get started with:
let nev = NEVec::new(42, vec![1, 2, 3]);
let singleton = NEVec::singleton(42);
let r#macro = nev![1, 2, 3];NEVec conforms to Index, IntoIterator, [Deref], and many more, so operations are as Vec-like as possible. They are also usually zero-cost.
let nev = nev![42, 1, 2, 3];
assert_eq!(nev[0], 42);
assert_eq!(nev.len(), 4);
assert_eq!(nev.into_iter().sum::<i32>(), 48);When the feature arbitrary is enabled, NEVec implements [arbitrary::Arbitrary]
for generation of randomly populated instances.
Structsยง
- NEVec
- Non-empty vector type.