]> git.lizzy.rs Git - rust.git/blob - src/liballoc/collections/mod.rs
Rollup merge of #70038 - DutchGhost:const-forget-tests, r=RalfJung
[rust.git] / src / liballoc / collections / mod.rs
1 //! Collection types.
2
3 #![stable(feature = "rust1", since = "1.0.0")]
4
5 pub mod binary_heap;
6 mod btree;
7 pub mod linked_list;
8 pub mod vec_deque;
9
10 #[stable(feature = "rust1", since = "1.0.0")]
11 pub mod btree_map {
12     //! A map based on a B-Tree.
13     #[stable(feature = "rust1", since = "1.0.0")]
14     pub use super::btree::map::*;
15 }
16
17 #[stable(feature = "rust1", since = "1.0.0")]
18 pub mod btree_set {
19     //! A set based on a B-Tree.
20     #[stable(feature = "rust1", since = "1.0.0")]
21     pub use super::btree::set::*;
22 }
23
24 #[stable(feature = "rust1", since = "1.0.0")]
25 #[doc(no_inline)]
26 pub use binary_heap::BinaryHeap;
27
28 #[stable(feature = "rust1", since = "1.0.0")]
29 #[doc(no_inline)]
30 pub use btree_map::BTreeMap;
31
32 #[stable(feature = "rust1", since = "1.0.0")]
33 #[doc(no_inline)]
34 pub use btree_set::BTreeSet;
35
36 #[stable(feature = "rust1", since = "1.0.0")]
37 #[doc(no_inline)]
38 pub use linked_list::LinkedList;
39
40 #[stable(feature = "rust1", since = "1.0.0")]
41 #[doc(no_inline)]
42 pub use vec_deque::VecDeque;
43
44 use crate::alloc::{Layout, LayoutErr};
45 use core::fmt::Display;
46
47 /// The error type for `try_reserve` methods.
48 #[derive(Clone, PartialEq, Eq, Debug)]
49 #[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
50 pub enum TryReserveError {
51     /// Error due to the computed capacity exceeding the collection's maximum
52     /// (usually `isize::MAX` bytes).
53     CapacityOverflow,
54
55     /// The memory allocator returned an error
56     AllocError {
57         /// The layout of allocation request that failed
58         layout: Layout,
59
60         #[doc(hidden)]
61         #[unstable(
62             feature = "container_error_extra",
63             issue = "none",
64             reason = "\
65             Enable exposing the allocator’s custom error value \
66             if an associated type is added in the future: \
67             https://github.com/rust-lang/wg-allocators/issues/23"
68         )]
69         non_exhaustive: (),
70     },
71 }
72
73 #[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
74 impl From<LayoutErr> for TryReserveError {
75     #[inline]
76     fn from(_: LayoutErr) -> Self {
77         TryReserveError::CapacityOverflow
78     }
79 }
80
81 #[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
82 impl Display for TryReserveError {
83     fn fmt(
84         &self,
85         fmt: &mut core::fmt::Formatter<'_>,
86     ) -> core::result::Result<(), core::fmt::Error> {
87         fmt.write_str("memory allocation failed")?;
88         let reason = match &self {
89             TryReserveError::CapacityOverflow => {
90                 " because the computed capacity exceeded the collection's maximum"
91             }
92             TryReserveError::AllocError { .. } => " because the memory allocator returned a error",
93         };
94         fmt.write_str(reason)
95     }
96 }
97
98 /// An intermediate trait for specialization of `Extend`.
99 #[doc(hidden)]
100 trait SpecExtend<I: IntoIterator> {
101     /// Extends `self` with the contents of the given iterator.
102     fn spec_extend(&mut self, iter: I);
103 }