1use crate::Alignment;
4
5#[cfg(doc)] use core::alloc::LayoutError;
6use core::fmt::{self, Debug, Display, Formatter};
7
8
9
10#[derive(Clone, Copy, Debug)] pub struct BannedZeroSizedAllocationsError;
16
17#[derive(Clone, Copy, Debug)] pub struct ExcessiveAlignmentRequestedError {
19 pub requested: Alignment,
20 pub supported: Alignment,
21}
22
23#[derive(Clone, Copy, Debug)] pub struct ExcessiveSliceRequestedError {
25 pub requested: usize,
26}
27
28impl Display for BannedZeroSizedAllocationsError { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "requested a 0-sized allocation, but those have inconsistent behavior with this allocator") } }
29impl Display for ExcessiveAlignmentRequestedError { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "requested {:?} alignment, but a maximum of {:?} is supported", self.requested, self.supported) } }
30impl Display for ExcessiveSliceRequestedError { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "requested {} elements, but that would result in a LayoutError", self.requested) } }
31impl From<BannedZeroSizedAllocationsError > for () { fn from(_: BannedZeroSizedAllocationsError) -> Self {} }
32impl From<ExcessiveAlignmentRequestedError> for () { fn from(_: ExcessiveAlignmentRequestedError) -> Self {} }
33impl From<ExcessiveSliceRequestedError > for () { fn from(_: ExcessiveSliceRequestedError) -> Self {} }
34#[cfg(feature = "std")] impl std::error::Error for BannedZeroSizedAllocationsError { fn description(&self) -> &str { "requested a 0-sized allocation, but those have inconsistent behavior with this allocator" } }
35#[cfg(feature = "std")] impl std::error::Error for ExcessiveAlignmentRequestedError { fn description(&self) -> &str { "requested more alignment than was supported" } }
36#[cfg(feature = "std")] impl std::error::Error for ExcessiveSliceRequestedError { fn description(&self) -> &str { "requested too many elements" } }
37#[cfg(allocator_api = "*")] impl From<BannedZeroSizedAllocationsError > for core::alloc::AllocError { fn from(_: BannedZeroSizedAllocationsError ) -> Self { core::alloc::AllocError } }
38#[cfg(allocator_api = "*")] impl From<ExcessiveAlignmentRequestedError> for core::alloc::AllocError { fn from(_: ExcessiveAlignmentRequestedError) -> Self { core::alloc::AllocError } }
39#[cfg(allocator_api = "*")] impl From<ExcessiveSliceRequestedError > for core::alloc::AllocError { fn from(_: ExcessiveSliceRequestedError ) -> Self { core::alloc::AllocError } }