3 #![stable(feature = "rust1", since = "1.0.0")]
5 #[cfg(not(no_global_oom_handling))]
7 #[cfg(not(no_global_oom_handling))]
9 #[cfg(not(no_global_oom_handling))]
11 #[cfg(not(no_global_oom_handling))]
14 #[cfg(not(no_global_oom_handling))]
15 #[stable(feature = "rust1", since = "1.0.0")]
17 //! A map based on a B-Tree.
18 #[stable(feature = "rust1", since = "1.0.0")]
19 pub use super::btree::map::*;
22 #[cfg(not(no_global_oom_handling))]
23 #[stable(feature = "rust1", since = "1.0.0")]
25 //! A set based on a B-Tree.
26 #[stable(feature = "rust1", since = "1.0.0")]
27 pub use super::btree::set::*;
30 #[cfg(not(no_global_oom_handling))]
31 #[stable(feature = "rust1", since = "1.0.0")]
33 pub use binary_heap::BinaryHeap;
35 #[cfg(not(no_global_oom_handling))]
36 #[stable(feature = "rust1", since = "1.0.0")]
38 pub use btree_map::BTreeMap;
40 #[cfg(not(no_global_oom_handling))]
41 #[stable(feature = "rust1", since = "1.0.0")]
43 pub use btree_set::BTreeSet;
45 #[cfg(not(no_global_oom_handling))]
46 #[stable(feature = "rust1", since = "1.0.0")]
48 pub use linked_list::LinkedList;
50 #[cfg(not(no_global_oom_handling))]
51 #[stable(feature = "rust1", since = "1.0.0")]
53 pub use vec_deque::VecDeque;
55 use crate::alloc::{Layout, LayoutError};
56 use core::fmt::Display;
58 /// The error type for `try_reserve` methods.
59 #[derive(Clone, PartialEq, Eq, Debug)]
60 #[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
61 pub struct TryReserveError {
62 kind: TryReserveErrorKind,
65 impl TryReserveError {
66 /// Details about the allocation that caused the error
69 feature = "try_reserve_kind",
70 reason = "Uncertain how much info should be exposed",
73 pub fn kind(&self) -> TryReserveErrorKind {
78 /// Details of the allocation that caused a `TryReserveError`
79 #[derive(Clone, PartialEq, Eq, Debug)]
81 feature = "try_reserve_kind",
82 reason = "Uncertain how much info should be exposed",
85 pub enum TryReserveErrorKind {
86 /// Error due to the computed capacity exceeding the collection's maximum
87 /// (usually `isize::MAX` bytes).
90 /// The memory allocator returned an error
92 /// The layout of allocation request that failed
97 feature = "container_error_extra",
100 Enable exposing the allocator’s custom error value \
101 if an associated type is added in the future: \
102 https://github.com/rust-lang/wg-allocators/issues/23"
109 feature = "try_reserve_kind",
110 reason = "Uncertain how much info should be exposed",
113 impl From<TryReserveErrorKind> for TryReserveError {
114 fn from(kind: TryReserveErrorKind) -> Self {
119 #[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
120 impl From<LayoutError> for TryReserveError {
121 /// Always evaluates to [`TryReserveErrorKind::CapacityOverflow`].
123 fn from(_: LayoutError) -> Self {
124 TryReserveErrorKind::CapacityOverflow.into()
128 #[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
129 impl Display for TryReserveError {
132 fmt: &mut core::fmt::Formatter<'_>,
133 ) -> core::result::Result<(), core::fmt::Error> {
134 fmt.write_str("memory allocation failed")?;
135 let reason = match self.kind {
136 TryReserveErrorKind::CapacityOverflow => {
137 " because the computed capacity exceeded the collection's maximum"
139 TryReserveErrorKind::AllocError { .. } => {
140 " because the memory allocator returned a error"
143 fmt.write_str(reason)
147 /// An intermediate trait for specialization of `Extend`.
149 trait SpecExtend<I: IntoIterator> {
150 /// Extends `self` with the contents of the given iterator.
151 fn spec_extend(&mut self, iter: I);