3 #![doc(html_root_url = "https://docs.rs/indexmap/1/")]
5 //! [`IndexMap`] is a hash table where the iteration order of the key-value
6 //! pairs is independent of the hash values of the keys.
8 //! [`IndexSet`] is a corresponding hash set using the same implementation and
9 //! with similar properties.
11 //! [`IndexMap`]: map/struct.IndexMap.html
12 //! [`IndexSet`]: set/struct.IndexSet.html
17 //! This version of indexmap requires Rust 1.18 or later, or 1.30+ for
18 //! development builds.
20 //! The indexmap 1.x release series will use a carefully considered version
21 //! upgrade policy, where in a later 1.x version, we will raise the minimum
22 //! required Rust version.
26 #[cfg(feature = "serde-1")]
35 // Placed after `map` and `set` so new `rayon` methods on the types
36 // are documented after the "normal" methods.
37 #[cfg(feature = "rayon")]
40 pub use equivalent::Equivalent;
41 pub use map::IndexMap;
42 pub use set::IndexSet;
44 // shared private items
46 /// Hash value newtype. Not larger than usize, since anything larger
47 /// isn't used for selecting position anyway.
48 #[derive(Copy, Debug)]
49 struct HashValue(usize);
53 fn get(self) -> usize { self.0 }
56 impl Clone for HashValue {
58 fn clone(&self) -> Self { *self }
60 impl PartialEq for HashValue {
62 fn eq(&self, rhs: &Self) -> bool {
67 #[derive(Copy, Clone, Debug)]
74 impl<K, V> Bucket<K, V> {
75 // field accessors -- used for `f` instead of closures in `.map(f)`
76 fn key_ref(&self) -> &K { &self.key }
77 fn value_ref(&self) -> &V { &self.value }
78 fn value_mut(&mut self) -> &mut V { &mut self.value }
79 fn key(self) -> K { self.key }
80 fn key_value(self) -> (K, V) { (self.key, self.value) }
81 fn refs(&self) -> (&K, &V) { (&self.key, &self.value) }
82 fn ref_mut(&mut self) -> (&K, &mut V) { (&self.key, &mut self.value) }
83 fn muts(&mut self) -> (&mut K, &mut V) { (&mut self.key, &mut self.value) }
88 fn into_entries(self) -> Vec<Self::Entry>;
89 fn as_entries(&self) -> &[Self::Entry];
90 fn as_entries_mut(&mut self) -> &mut [Self::Entry];
91 fn with_entries<F>(&mut self, f: F)
92 where F: FnOnce(&mut [Self::Entry]);