1 // SPDX-License-Identifier: Apache-2.0 OR MIT
5 #![stable(feature = "rust1", since = "1.0.0")]
7 #[cfg(not(no_global_oom_handling))]
9 #[cfg(not(no_global_oom_handling))]
11 #[cfg(not(no_global_oom_handling))]
13 #[cfg(not(no_global_oom_handling))]
16 #[cfg(not(no_global_oom_handling))]
17 #[stable(feature = "rust1", since = "1.0.0")]
19 //! An ordered map based on a B-Tree.
20 #[stable(feature = "rust1", since = "1.0.0")]
21 pub use super::btree::map::*;
24 #[cfg(not(no_global_oom_handling))]
25 #[stable(feature = "rust1", since = "1.0.0")]
27 //! An ordered set based on a B-Tree.
28 #[stable(feature = "rust1", since = "1.0.0")]
29 pub use super::btree::set::*;
32 #[cfg(not(no_global_oom_handling))]
33 #[stable(feature = "rust1", since = "1.0.0")]
35 pub use binary_heap::BinaryHeap;
37 #[cfg(not(no_global_oom_handling))]
38 #[stable(feature = "rust1", since = "1.0.0")]
40 pub use btree_map::BTreeMap;
42 #[cfg(not(no_global_oom_handling))]
43 #[stable(feature = "rust1", since = "1.0.0")]
45 pub use btree_set::BTreeSet;
47 #[cfg(not(no_global_oom_handling))]
48 #[stable(feature = "rust1", since = "1.0.0")]
50 pub use linked_list::LinkedList;
52 #[cfg(not(no_global_oom_handling))]
53 #[stable(feature = "rust1", since = "1.0.0")]
55 pub use vec_deque::VecDeque;
57 use crate::alloc::{Layout, LayoutError};
58 use core::fmt::Display;
60 /// The error type for `try_reserve` methods.
61 #[derive(Clone, PartialEq, Eq, Debug)]
62 #[stable(feature = "try_reserve", since = "1.57.0")]
63 pub struct TryReserveError {
64 kind: TryReserveErrorKind,
67 impl TryReserveError {
68 /// Details about the allocation that caused the error
72 feature = "try_reserve_kind",
73 reason = "Uncertain how much info should be exposed",
76 pub fn kind(&self) -> TryReserveErrorKind {
81 /// Details of the allocation that caused a `TryReserveError`
82 #[derive(Clone, PartialEq, Eq, Debug)]
84 feature = "try_reserve_kind",
85 reason = "Uncertain how much info should be exposed",
88 pub enum TryReserveErrorKind {
89 /// Error due to the computed capacity exceeding the collection's maximum
90 /// (usually `isize::MAX` bytes).
93 /// The memory allocator returned an error
95 /// The layout of allocation request that failed
100 feature = "container_error_extra",
103 Enable exposing the allocator’s custom error value \
104 if an associated type is added in the future: \
105 https://github.com/rust-lang/wg-allocators/issues/23"
112 feature = "try_reserve_kind",
113 reason = "Uncertain how much info should be exposed",
116 impl From<TryReserveErrorKind> for TryReserveError {
118 fn from(kind: TryReserveErrorKind) -> Self {
123 #[unstable(feature = "try_reserve_kind", reason = "new API", issue = "48043")]
124 impl From<LayoutError> for TryReserveErrorKind {
125 /// Always evaluates to [`TryReserveErrorKind::CapacityOverflow`].
127 fn from(_: LayoutError) -> Self {
128 TryReserveErrorKind::CapacityOverflow
132 #[stable(feature = "try_reserve", since = "1.57.0")]
133 impl Display for TryReserveError {
136 fmt: &mut core::fmt::Formatter<'_>,
137 ) -> core::result::Result<(), core::fmt::Error> {
138 fmt.write_str("memory allocation failed")?;
139 let reason = match self.kind {
140 TryReserveErrorKind::CapacityOverflow => {
141 " because the computed capacity exceeded the collection's maximum"
143 TryReserveErrorKind::AllocError { .. } => {
144 " because the memory allocator returned an error"
147 fmt.write_str(reason)
151 /// An intermediate trait for specialization of `Extend`.
153 trait SpecExtend<I: IntoIterator> {
154 /// Extends `self` with the contents of the given iterator.
155 fn spec_extend(&mut self, iter: I);
158 #[stable(feature = "try_reserve", since = "1.57.0")]
159 impl core::error::Error for TryReserveError {}