1#![cfg_attr(not(doc), no_std)]
13#![cfg_attr(
14 feature = "nightly",
15 feature(
16 core_intrinsics,
17 dropck_eyepatch,
18 min_specialization,
19 trivial_clone,
20 extend_one,
21 strict_provenance_lints
22 )
23)]
24#![cfg_attr(feature = "nightly", warn(implicit_provenance_casts))]
25#![cfg_attr(feature = "rustc-dep-of-std", feature(rustc_attrs))]
26#![cfg_attr(feature = "nightly", expect(internal_features))]
27#![cfg_attr(
28 all(feature = "nightly", feature = "default-hasher"),
29 feature(hasher_prefixfree_extras)
30)]
31
32#[cfg(test)]
33#[macro_use]
34extern crate std;
35
36#[cfg_attr(test, macro_use)]
37#[cfg_attr(feature = "rustc-dep-of-std", allow(unused_extern_crates))]
38extern crate alloc as stdalloc;
39
40#[doc = include_str!("../README.md")]
41#[cfg(doctest)]
42pub struct ReadmeDoctests;
43
44#[macro_use]
45mod macros;
46
47mod alloc;
48mod control;
49mod hasher;
50mod raw;
51mod util;
52
53mod external_trait_impls;
54mod map;
55#[cfg(feature = "raw-entry")]
56mod raw_entry;
57#[cfg(feature = "rustc-internal-api")]
58mod rustc_entry;
59mod scopeguard;
60mod set;
61mod table;
62
63pub use crate::hasher::DefaultHashBuilder;
64#[cfg(feature = "default-hasher")]
65pub use crate::hasher::DefaultHasher;
66
67pub mod hash_map {
68 pub use crate::map::*;
70
71 #[cfg(feature = "rustc-internal-api")]
72 pub use crate::rustc_entry::*;
73
74 #[cfg(feature = "rayon")]
75 pub mod rayon {
81 pub use crate::external_trait_impls::rayon::map::*;
82 }
83}
84pub mod hash_set {
85 pub use crate::set::*;
87
88 #[cfg(feature = "rayon")]
89 pub mod rayon {
95 pub use crate::external_trait_impls::rayon::set::*;
96 }
97}
98pub mod hash_table {
99 pub use crate::table::*;
101
102 #[cfg(feature = "rayon")]
103 pub mod rayon {
109 pub use crate::external_trait_impls::rayon::table::*;
110 }
111}
112
113pub use crate::map::HashMap;
114pub use crate::set::HashSet;
115pub use crate::table::HashTable;
116
117#[cfg(feature = "equivalent")]
118pub use equivalent::Equivalent;
119
120#[cfg(not(feature = "equivalent"))]
122pub trait Equivalent<K: ?Sized> {
134 fn equivalent(&self, key: &K) -> bool;
143}
144
145#[cfg(not(feature = "equivalent"))]
146impl<Q: ?Sized, K: ?Sized> Equivalent<K> for Q
147where
148 Q: Eq,
149 K: core::borrow::Borrow<Q>,
150{
151 fn equivalent(&self, key: &K) -> bool {
152 self == key.borrow()
153 }
154}
155
156#[derive(Clone, PartialEq, Eq, Debug)]
158pub enum TryReserveError {
159 CapacityOverflow,
162
163 AllocError {
165 layout: core::alloc::Layout,
167 },
168}
169
170impl core::fmt::Display for TryReserveError {
172 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
173 f.write_str("memory allocation failed")?;
174 let reason = match self {
175 TryReserveError::CapacityOverflow => {
176 " because the computed capacity exceeded the collection's maximum"
177 }
178 TryReserveError::AllocError { .. } => " because the memory allocator returned an error",
179 };
180 f.write_str(reason)
181 }
182}
183
184impl core::error::Error for TryReserveError {}