non-non-full 0.0.1

Vec and String wrappers that assert the containers are always non-empty (or, ahem, non-non-full)
Documentation
  • Coverage
  • 66.67%
    2 out of 3 items documented1 out of 1 items with examples
  • Size
  • Source code size: 14.63 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.04 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • SergeyKasmy

non-non-full

Container types that guarantee non-emptiness.

This crate provides wrapper types around Vec and String that ensure they can never be empty. The name "non-non-full" is a playful way of saying "not empty" (i.e., full).

Features

  • NonEmptyVec<T>: A vector that always contains at least one element
  • NonEmptyString: A string that always contains at least one character
  • Optional serde support via the "serde" feature

Example

use non_non_full::{NonEmptyVec, NonEmptyString};

// Creating non-empty containers
let vec = NonEmptyVec::new_one(42);
let string = NonEmptyString::new("Hello".to_string()).unwrap();

// Operations that would make the container empty are prevented
let mut vec = NonEmptyVec::new(vec![1, 2]).unwrap();
assert_eq!(vec.pop(), Some(2)); // Allowed - vec still contains [1]
assert_eq!(vec.pop(), None);    // Prevented - would make vec empty

License: MPL-2.0