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