1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//! Collection types.

use crate::alloc::{AllocRef, CapacityOverflow, LayoutErr, NonZeroLayout};
pub use liballoc::collections::{binary_heap, btree_map, btree_set, linked_list, vec_deque};

#[doc(no_inline)]
pub use self::{
    binary_heap::BinaryHeap,
    btree_map::BTreeMap,
    btree_set::BTreeSet,
    linked_list::LinkedList,
    vec_deque::VecDeque,
};

/// Augments `AllocErr` with a `CapacityOverflow` variant.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum CollectionAllocErr<A: AllocRef> {
    /// Error due to the computed capacity exceeding the collection's maximum
    /// (usually `isize::MAX` bytes).
    CapacityOverflow,

    /// The memory allocator returned an error
    AllocError {
        /// The layout of allocation request that failed
        layout: NonZeroLayout,

        /// Error returned by the allocator
        inner: A::Error,
    },
}

impl<A: AllocRef> From<CapacityOverflow> for CollectionAllocErr<A> {
    #[inline]
    #[must_use]
    fn from(_: CapacityOverflow) -> Self {
        Self::CapacityOverflow
    }
}

impl<A: AllocRef> From<LayoutErr> for CollectionAllocErr<A> {
    #[inline]
    #[must_use]
    fn from(_: LayoutErr) -> Self {
        Self::CapacityOverflow
    }
}