nonempty

Crates.iononempty
lib.rsnonempty
version0.10.0
sourcesrc
created_at2019-11-07 16:55:55.006216
updated_at2024-02-29 14:08:01.905934
descriptionCorrect by construction non-empty vector
homepage
repositoryhttps://github.com/cloudhead/nonempty
max_upload_size
id179058
size50,152
Fintan Halpenny (FintanH)

documentation

README

Correct by Construction Non-Empty List

This package exposes a type NonEmpty<T> with a data representation that guarantees non-emptiness statically:

struct NonEmpty<T>(T, Vec<T>)

The library is meant to have an interface similar to std::vec::Vec:

use nonempty::NonEmpty;

let mut l = NonEmpty::new(42);

assert_eq!(l.first(), &42);

l.push(36);
l.push(58);

let v: Vec<i32> = l.into();
assert_eq!(v, vec![42, 36, 58]);
Commit count: 86

cargo fmt