nonempty-containers

Crates.iononempty-containers
lib.rsnonempty-containers
version0.2.3
created_at2025-02-07 15:08:10.433888+00
updated_at2025-03-09 13:59:42.215999+00
descriptionFast, zero-cost conversion, and fully inter-operable nonempty container types.
homepage
repositoryhttps://github.com/Funky-Farm/nonempty-containers
max_upload_size
id1547042
size28,698
Lancelot Liu (lancylot2004)

documentation

README

Non-Empty Containers

A simple set of non-empty alternatives to standard containers in Rust, including NonEmptyVec.

Getting Started

Add this to your Cargo.toml:

# Cargo.toml

[dependencies]
nonempty-containers = "0.0.3"

The non-empty containers behave like their standard counterparts:

use nonempty_containers::NonEmptyVec;

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

nev.push(2);
nev.pop();
nev.pop();
assert_eq!(nev, NonEmptyVec::singleton(42));

// Errors!
nev.pop();

Automatically Deriving Arbitrary

All non-empty containers can automatically derive Arbitrary, so long as the contained type also implements Arbitrary. This is useful for property-based testing, such as with arbtest.

# Cargo.toml

[dependencies]
nonempty-containers = { version = "0.0.2", features = ["arbitrary"] }

And then you can simply add #[derive(Arbitrary)] annotations to your types:

// pixels.rs

use arbitrary::Arbitrary;

#[derive(Arbitrary)]
pub struct Items(NonEmptyVec<u32>);
Commit count: 29

cargo fmt