non_non_full/lib.rs
1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5 */
6
7//! Container types that guarantee non-emptiness.
8//!
9//! This crate provides wrapper types around `Vec` and `String` that ensure they can never be empty.
10//! The name "non-non-full" is a playful way of saying "not empty" (i.e., full).
11//!
12//! # Features
13//!
14//! - `NonEmptyVec<T>`: A vector that always contains at least one element
15//! - `NonEmptyString`: A string that always contains at least one character
16//! - Optional serde support via the "serde" feature
17//!
18//! # Example
19//!
20//! ```
21//! use non_non_full::{NonEmptyVec, NonEmptyString};
22//!
23//! // Creating non-empty containers
24//! let vec = NonEmptyVec::new_one(42);
25//! let string = NonEmptyString::new("Hello".to_string()).unwrap();
26//!
27//! // Operations that would make the container empty are prevented
28//! let mut vec = NonEmptyVec::new(vec![1, 2]).unwrap();
29//! assert_eq!(vec.pop(), Some(2)); // Allowed - vec still contains [1]
30//! assert_eq!(vec.pop(), None); // Prevented - would make vec empty
31//! ```
32
33mod string;
34mod vec;
35
36pub use self::{string::NonEmptyString, vec::NonEmptyVec};