non_empty_collections/lib.rs
1//! Non-empty hash map and hash set implementations based on [`indexmap::IndexMap`] and
2//! [`indexmap::IndexSet`] respectively, which are guaranteed to be non-empty by the type system of
3//! Rust.
4//!
5//! [](https://gitlab.com/mexus/non-empty-collections/commits/master)
6//! [](https://crates.io/crates/non-empty-collections)
7//! [](https://docs.rs/non-empty-collections)
8//!
9//! [[Release docs]](https://docs.rs/non-empty-collections/)
10//!
11//! [[Master docs]](https://mexus.gitlab.io/non-empty-collections/non_empty_collections/)
12//!
13//! Currently not all the methods of IndexMap or IndexSet are ported to NonEmptyIndexMap and
14//! NonEmptyIndexSet, so if you are missing something, PRs are welcome! :)
15//!
16//! Right now both implementations are too naïve: non-emptiness is achieved by declaring map and
17//! set types as a pair of an element and the rest of the collection. While the idea itself is not
18//! bad, it adds an additional overhead on basically every operation since we have to execute
19//! everything twice: on the first element and then on the rest.
20//!
21//! Both collections are coming with serde de- and serializers, but if you don't need them and want
22//! to save some space and/or compilation time you can always disable it by disabling a feature
23//! `serde_support` (which is *on* by default).
24
25#![deny(missing_docs)]
26
27extern crate indexmap;
28
29#[cfg(feature = "serde_support")]
30extern crate serde;
31
32mod error;
33pub mod index_map;
34pub mod index_set;
35
36/// Estimates a size of an interator using a *size hint* as `(lower + upper)/2`.
37fn estimated_size(i: &impl Iterator) -> Option<usize> {
38 let (lower, upper) = i.size_hint();
39 upper.map(|upper| (upper + lower) / 2)
40}
41
42pub use error::Error;
43pub use index_map::NonEmptyIndexMap;
44pub use index_set::NonEmptyIndexSet;