1#![stable(feature = "rust1", since = "1.0.0")]
7
8#[cfg(not(no_global_oom_handling))]
9pub mod binary_heap;
10#[cfg(not(no_global_oom_handling))]
11mod btree;
12#[cfg(not(no_global_oom_handling))]
13pub mod linked_list;
14#[cfg(not(no_global_oom_handling))]
15pub mod vec_deque;
16
17#[cfg(not(no_global_oom_handling))]
18#[stable(feature = "rust1", since = "1.0.0")]
19pub mod btree_map {
20 #[stable(feature = "rust1", since = "1.0.0")]
22 #[cfg(not(test))]
23 pub use super::btree::map::*;
24}
25
26#[cfg(not(no_global_oom_handling))]
27#[stable(feature = "rust1", since = "1.0.0")]
28pub mod btree_set {
29 #[stable(feature = "rust1", since = "1.0.0")]
31 #[cfg(not(test))]
32 pub use super::btree::set::*;
33}
34
35#[cfg(not(test))]
36use core::fmt::Display;
37
38#[cfg(not(no_global_oom_handling))]
39#[stable(feature = "rust1", since = "1.0.0")]
40#[doc(no_inline)]
41#[cfg(not(test))]
42pub use binary_heap::BinaryHeap;
43#[cfg(not(no_global_oom_handling))]
44#[stable(feature = "rust1", since = "1.0.0")]
45#[doc(no_inline)]
46#[cfg(not(test))]
47pub use btree_map::BTreeMap;
48#[cfg(not(no_global_oom_handling))]
49#[stable(feature = "rust1", since = "1.0.0")]
50#[doc(no_inline)]
51#[cfg(not(test))]
52pub use btree_set::BTreeSet;
53#[cfg(not(no_global_oom_handling))]
54#[stable(feature = "rust1", since = "1.0.0")]
55#[doc(no_inline)]
56#[cfg(not(test))]
57pub use linked_list::LinkedList;
58#[cfg(not(no_global_oom_handling))]
59#[stable(feature = "rust1", since = "1.0.0")]
60#[doc(no_inline)]
61#[cfg(not(test))]
62pub use vec_deque::VecDeque;
63
64#[cfg(not(test))]
65use crate::alloc::{Layout, LayoutError};
66
67#[derive(#[automatically_derived]
#[stable(feature = "try_reserve", since = "1.57.0")]
impl ::core::clone::Clone for TryReserveError {
#[inline]
fn clone(&self) -> TryReserveError {
TryReserveError { kind: ::core::clone::Clone::clone(&self.kind) }
}
}Clone, #[automatically_derived]
#[stable(feature = "try_reserve", since = "1.57.0")]
impl ::core::cmp::PartialEq for TryReserveError {
#[inline]
fn eq(&self, other: &TryReserveError) -> bool { self.kind == other.kind }
}PartialEq, #[automatically_derived]
#[stable(feature = "try_reserve", since = "1.57.0")]
impl ::core::cmp::Eq for TryReserveError {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<TryReserveErrorKind>;
}
}Eq, #[automatically_derived]
#[stable(feature = "try_reserve", since = "1.57.0")]
impl ::core::fmt::Debug for TryReserveError {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f,
"TryReserveError", "kind", &&self.kind)
}
}Debug)]
69#[stable(feature = "try_reserve", since = "1.57.0")]
70#[cfg(not(test))]
71pub struct TryReserveError {
72 kind: TryReserveErrorKind,
73}
74
75#[cfg(test)]
76pub use realalloc::collections::TryReserveError;
77
78#[cfg(not(test))]
79impl TryReserveError {
80 #[inline]
82 #[must_use]
83 #[unstable(
84 feature = "try_reserve_kind",
85 reason = "Uncertain how much info should be exposed",
86 issue = "48043"
87 )]
88 #[rustc_const_unstable(feature = "const_heap", issue = "79597")]
89 pub const fn kind(&self) -> TryReserveErrorKind {
90 self.kind.clone()
91 }
92}
93
94#[derive(#[automatically_derived]
#[unstable(feature = "try_reserve_kind", reason =
"Uncertain how much info should be exposed", issue = "48043")]
impl ::core::cmp::PartialEq for TryReserveErrorKind {
#[inline]
fn eq(&self, other: &TryReserveErrorKind) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(TryReserveErrorKind::AllocError {
layout: __self_0, non_exhaustive: __self_1 },
TryReserveErrorKind::AllocError {
layout: __arg1_0, non_exhaustive: __arg1_1 }) =>
__self_1 == __arg1_1 && __self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
#[unstable(feature = "try_reserve_kind", reason =
"Uncertain how much info should be exposed", issue = "48043")]
impl ::core::cmp::Eq for TryReserveErrorKind {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Layout>;
let _: ::core::cmp::AssertParamIsEq<()>;
}
}Eq, #[automatically_derived]
#[unstable(feature = "try_reserve_kind", reason =
"Uncertain how much info should be exposed", issue = "48043")]
impl ::core::fmt::Debug for TryReserveErrorKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
TryReserveErrorKind::CapacityOverflow =>
::core::fmt::Formatter::write_str(f, "CapacityOverflow"),
TryReserveErrorKind::AllocError {
layout: __self_0, non_exhaustive: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"AllocError", "layout", __self_0, "non_exhaustive",
&__self_1),
}
}
}Debug)]
96#[unstable(
97 feature = "try_reserve_kind",
98 reason = "Uncertain how much info should be exposed",
99 issue = "48043"
100)]
101#[cfg(not(test))]
102pub enum TryReserveErrorKind {
103 CapacityOverflow,
106
107 AllocError {
109 layout: Layout,
111
112 #[doc(hidden)]
113 #[unstable(
114 feature = "container_error_extra",
115 issue = "none",
116 reason = "\
117 Enable exposing the allocator’s custom error value \
118 if an associated type is added in the future: \
119 https://github.com/rust-lang/wg-allocators/issues/23"
120 )]
121 non_exhaustive: (),
122 },
123}
124
125#[unstable(
126 feature = "try_reserve_kind",
127 reason = "Uncertain how much info should be exposed",
128 issue = "48043"
129)]
130#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
131#[cfg(not(test))]
132impl const Clone for TryReserveErrorKind {
133 fn clone(&self) -> Self {
134 match self {
135 TryReserveErrorKind::CapacityOverflow => TryReserveErrorKind::CapacityOverflow,
136 TryReserveErrorKind::AllocError { layout, non_exhaustive: () } => {
137 TryReserveErrorKind::AllocError { layout: *layout, non_exhaustive: () }
138 }
139 }
140 }
141}
142
143#[cfg(test)]
144pub use realalloc::collections::TryReserveErrorKind;
145
146#[unstable(
147 feature = "try_reserve_kind",
148 reason = "Uncertain how much info should be exposed",
149 issue = "48043"
150)]
151#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
152#[cfg(not(test))]
153impl const From<TryReserveErrorKind> for TryReserveError {
154 #[inline]
155 fn from(kind: TryReserveErrorKind) -> Self {
156 Self { kind }
157 }
158}
159
160#[unstable(feature = "try_reserve_kind", issue = "48043")]
161#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
162#[cfg(not(test))]
163impl const From<LayoutError> for TryReserveErrorKind {
164 #[inline]
166 fn from(_: LayoutError) -> Self {
167 TryReserveErrorKind::CapacityOverflow
168 }
169}
170
171#[stable(feature = "try_reserve", since = "1.57.0")]
172#[cfg(not(test))]
173impl Display for TryReserveError {
174 fn fmt(
175 &self,
176 fmt: &mut core::fmt::Formatter<'_>,
177 ) -> core::result::Result<(), core::fmt::Error> {
178 fmt.write_str("memory allocation failed")?;
179 let reason = match self.kind {
180 TryReserveErrorKind::CapacityOverflow => {
181 " because the computed capacity exceeded the collection's maximum"
182 }
183 TryReserveErrorKind::AllocError { .. } => {
184 " because the memory allocator returned an error"
185 }
186 };
187 fmt.write_str(reason)
188 }
189}
190
191#[doc(hidden)]
193#[cfg(not(no_global_oom_handling))]
194trait SpecExtend<I: IntoIterator> {
195 fn spec_extend(&mut self, iter: I);
197}
198
199#[stable(feature = "try_reserve", since = "1.57.0")]
200#[cfg(not(test))]
201impl core::error::Error for TryReserveError {}