empty_collections/lib.rs
1//! Empty collections - guaranteed to have nothing!
2//!
3//! You may be familiar with the concept of [nonempty-collections][ne]. The
4//! `empty-collections` crate provides the sister-concept; collections which
5//! contain nothing, and never will.
6//!
7//! Why, you ask? That is a good question.
8//!
9//! # Examples
10//!
11//! ```
12//! use empty_collections::*;
13//!
14//! let v: EVec<usize> = EVec::new();
15//! assert!(v.is_empty());
16//! ```
17//!
18//! See the documentation for [`EVec`], [`EMap`], and [`ESet`] for more examples
19//! of their extensive APIs.
20//!
21//! # Iteration
22//!
23//! The iterators in this crate are the fastest in the entire Rust ecosystem,
24//! able to traverse their entire stream in constant time. Simply amazing.
25//!
26//! ```
27//! use empty_collections::*;
28//!
29//! let v: EVec<i32> = EVec::new();
30//! assert_eq!(0, v.into_iter().sum());
31//! ```
32//!
33//! # Features
34//!
35//! - `serde`: Guarantee that collections you send/receive over the wire are empty.
36//!
37//! [ne]: https://lib.rs/crates/nonempty-collections
38
39#![warn(missing_docs)]
40
41mod map;
42mod set;
43mod vector;
44
45use std::marker::PhantomData;
46
47pub use map::EMap;
48pub use set::ESet;
49pub use vector::EVec;
50
51/// An empty [`Iterator`].
52pub struct Empty<T> {
53 phantom: PhantomData<T>,
54}
55
56impl<T> Empty<T> {
57 pub(crate) fn new() -> Empty<T> {
58 Empty {
59 phantom: PhantomData,
60 }
61 }
62}
63
64impl<T> Iterator for Empty<T> {
65 type Item = T;
66
67 fn next(&mut self) -> Option<Self::Item> {
68 None
69 }
70}