1#![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 allocator_api,
22 strict_provenance_lints
23 )
24)]
25#![cfg_attr(feature = "nightly", warn(fuzzy_provenance_casts))]
26#![cfg_attr(feature = "rustc-dep-of-std", feature(rustc_attrs))]
27#![cfg_attr(feature = "nightly", expect(internal_features))]
28#![cfg_attr(
29 all(feature = "nightly", target_arch = "loongarch64"),
30 feature(stdarch_loongarch)
31)]
32#![cfg_attr(
33 all(feature = "nightly", feature = "default-hasher"),
34 feature(hasher_prefixfree_extras)
35)]
36
37#![allow(rustdoc::broken_intra_doc_links)]
38
39#[cfg(test)]
40#[macro_use]
41extern crate std;
42
43#[cfg_attr(test, macro_use)]
44#[cfg_attr(feature = "rustc-dep-of-std", allow(unused_extern_crates))]
45extern crate alloc as stdalloc;
46
47#[doc = include_str!("../README.md")]
48#[cfg(doctest)]
49pub struct ReadmeDoctests;
50
51#[macro_use]
52mod macros;
53
54mod alloc;
55mod control;
56mod hasher;
57mod raw;
58mod util;
59
60mod external_trait_impls;
61mod map;
62#[cfg(feature = "raw-entry")]
63mod raw_entry;
64#[cfg(feature = "rustc-internal-api")]
65mod rustc_entry;
66mod scopeguard;
67mod set;
68mod table;
69
70pub use crate::hasher::DefaultHashBuilder;
71#[cfg(feature = "default-hasher")]
72pub use crate::hasher::DefaultHasher;
73
74pub mod hash_map {
75 pub use crate::map::*;
77
78 #[cfg(feature = "rustc-internal-api")]
79 pub use crate::rustc_entry::*;
80
81 #[cfg(feature = "rayon")]
82 pub mod rayon {
88 pub use crate::external_trait_impls::rayon::map::*;
89 }
90}
91pub mod hash_set {
92 pub use crate::set::*;
94
95 #[cfg(feature = "rayon")]
96 pub mod rayon {
102 pub use crate::external_trait_impls::rayon::set::*;
103 }
104}
105pub mod hash_table {
106 pub use crate::table::*;
108
109 #[cfg(feature = "rayon")]
110 pub mod rayon {
116 pub use crate::external_trait_impls::rayon::table::*;
117 }
118}
119
120pub use crate::map::HashMap;
121pub use crate::set::HashSet;
122pub use crate::table::HashTable;
123
124#[cfg(feature = "equivalent")]
125pub use equivalent::Equivalent;
126
127#[cfg(not(feature = "equivalent"))]
129pub trait Equivalent<K: ?Sized> {
141 fn equivalent(&self, key: &K) -> bool;
150}
151
152#[cfg(not(feature = "equivalent"))]
153impl<Q: ?Sized, K: ?Sized> Equivalent<K> for Q
154where
155 Q: Eq,
156 K: core::borrow::Borrow<Q>,
157{
158 fn equivalent(&self, key: &K) -> bool {
159 self == key.borrow()
160 }
161}
162
163#[derive(Clone, PartialEq, Eq, Debug)]
165pub enum TryReserveError {
166 CapacityOverflow,
169
170 AllocError {
172 layout: stdalloc::alloc::Layout,
174 },
175}
176
177impl core::fmt::Display for TryReserveError {
179 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
180 f.write_str("memory allocation failed")?;
181 let reason = match self {
182 TryReserveError::CapacityOverflow => {
183 " because the computed capacity exceeded the collection's maximum"
184 }
185 TryReserveError::AllocError { .. } => " because the memory allocator returned an error",
186 };
187 f.write_str(reason)
188 }
189}
190
191impl core::error::Error for TryReserveError {}