Module nonemptyvec

Source
Expand description

A non-empty vector type that guarantees at least one element is present. NonEmptyVec has an interface similar to Vec with additional methods to enforce the invariant. Get started with:

let nev = NonEmptyVec::new(42, vec![1, 2, 3]);
let singleton = NonEmptyVec::singleton(42);

NonEmptyVec conforms to Index, IntoIterator, Deref, and many more, so operations are as Vec-like as possible. They are also usually zero-cost.

let nev = NonEmptyVec::new(42, vec![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, NonEmptyVec implements [arbitrary::Arbitrary] for generation of randomly populated instances.

Structs§

NonEmptyVec
Non-empty vector type.

Enums§

NonEmptyError
Errors that can occur when working with NonEmptyVec.