|
| 1 | +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +//! Collection types. |
| 12 | +
|
| 13 | +#![stable(feature = "rust1", since = "1.0.0")] |
| 14 | + |
| 15 | +pub mod binary_heap; |
| 16 | +mod btree; |
| 17 | +pub mod linked_list; |
| 18 | +pub mod vec_deque; |
| 19 | + |
| 20 | +#[stable(feature = "rust1", since = "1.0.0")] |
| 21 | +pub mod btree_map { |
| 22 | + //! A map based on a B-Tree. |
| 23 | + #[stable(feature = "rust1", since = "1.0.0")] |
| 24 | + pub use super::btree::map::*; |
| 25 | +} |
| 26 | + |
| 27 | +#[stable(feature = "rust1", since = "1.0.0")] |
| 28 | +pub mod btree_set { |
| 29 | + //! A set based on a B-Tree. |
| 30 | + #[stable(feature = "rust1", since = "1.0.0")] |
| 31 | + pub use super::btree::set::*; |
| 32 | +} |
| 33 | + |
| 34 | +#[stable(feature = "rust1", since = "1.0.0")] |
| 35 | +#[doc(no_inline)] |
| 36 | +pub use self::binary_heap::BinaryHeap; |
| 37 | + |
| 38 | +#[stable(feature = "rust1", since = "1.0.0")] |
| 39 | +#[doc(no_inline)] |
| 40 | +pub use self::btree_map::BTreeMap; |
| 41 | + |
| 42 | +#[stable(feature = "rust1", since = "1.0.0")] |
| 43 | +#[doc(no_inline)] |
| 44 | +pub use self::btree_set::BTreeSet; |
| 45 | + |
| 46 | +#[stable(feature = "rust1", since = "1.0.0")] |
| 47 | +#[doc(no_inline)] |
| 48 | +pub use self::linked_list::LinkedList; |
| 49 | + |
| 50 | +#[stable(feature = "rust1", since = "1.0.0")] |
| 51 | +#[doc(no_inline)] |
| 52 | +pub use self::vec_deque::VecDeque; |
| 53 | + |
| 54 | +use alloc::{AllocErr, LayoutErr}; |
| 55 | + |
| 56 | +/// Augments `AllocErr` with a CapacityOverflow variant. |
| 57 | +#[derive(Clone, PartialEq, Eq, Debug)] |
| 58 | +#[unstable(feature = "try_reserve", reason = "new API", issue="48043")] |
| 59 | +pub enum CollectionAllocErr { |
| 60 | + /// Error due to the computed capacity exceeding the collection's maximum |
| 61 | + /// (usually `isize::MAX` bytes). |
| 62 | + CapacityOverflow, |
| 63 | + /// Error due to the allocator (see the `AllocErr` type's docs). |
| 64 | + AllocErr, |
| 65 | +} |
| 66 | + |
| 67 | +#[unstable(feature = "try_reserve", reason = "new API", issue="48043")] |
| 68 | +impl From<AllocErr> for CollectionAllocErr { |
| 69 | + #[inline] |
| 70 | + fn from(AllocErr: AllocErr) -> Self { |
| 71 | + CollectionAllocErr::AllocErr |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +#[unstable(feature = "try_reserve", reason = "new API", issue="48043")] |
| 76 | +impl From<LayoutErr> for CollectionAllocErr { |
| 77 | + #[inline] |
| 78 | + fn from(_: LayoutErr) -> Self { |
| 79 | + CollectionAllocErr::CapacityOverflow |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +/// An intermediate trait for specialization of `Extend`. |
| 84 | +#[doc(hidden)] |
| 85 | +trait SpecExtend<I: IntoIterator> { |
| 86 | + /// Extends `self` with the contents of the given iterator. |
| 87 | + fn spec_extend(&mut self, iter: I); |
| 88 | +} |
0 commit comments