Bug 1608150 [wpt PR 21112] - Add missing space in `./wpt lint` command line docs...
[gecko.git] / third_party / rust / indexmap / src / lib.rs
blobcb28caf854f2ba69369fb756c63ba5593eb89463
2 #![deny(unsafe_code)]
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.
7 //!
8 //! [`IndexSet`] is a corresponding hash set using the same implementation and
9 //! with similar properties.
10 //!
11 //! [`IndexMap`]: map/struct.IndexMap.html
12 //! [`IndexSet`]: set/struct.IndexSet.html
13 //!
14 //!
15 //! ## Rust Version
16 //!
17 //! This version of indexmap requires Rust 1.18 or later, or 1.30+ for
18 //! development builds.
19 //!
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.
24 #[macro_use]
25 mod macros;
26 #[cfg(feature = "serde-1")]
27 mod serde;
28 mod util;
29 mod equivalent;
30 mod mutable_keys;
32 pub mod set;
33 pub mod map;
35 // Placed after `map` and `set` so new `rayon` methods on the types
36 // are documented after the "normal" methods.
37 #[cfg(feature = "rayon")]
38 mod 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);
51 impl HashValue {
52     #[inline(always)]
53     fn get(self) -> usize { self.0 }
56 impl Clone for HashValue {
57     #[inline]
58     fn clone(&self) -> Self { *self }
60 impl PartialEq for HashValue {
61     #[inline]
62     fn eq(&self, rhs: &Self) -> bool {
63         self.0 == rhs.0
64     }
67 #[derive(Copy, Clone, Debug)]
68 struct Bucket<K, V> {
69     hash: HashValue,
70     key: K,
71     value: V,
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) }
86 trait Entries {
87     type Entry;
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]);