packed_ptr/
error.rs

1use core::fmt::{Debug, Display, Formatter};
2
3/// Error type for [`PackedPtr::new`] & [`TypedPackedPtr::new`].
4///
5/// [`PackedPtr::new`]: crate::PackedPtr::new
6/// [`TypedPackedPtr::new`]: crate::TypedPackedPtr::new
7#[derive(Debug, Copy, Clone, Eq, PartialEq)]
8pub enum PackedPtrError {
9    /// The address is not aligned to the required alignment.
10    UnalignedAddress,
11    /// The data is too large to pack into the pointer.
12    DataOverflow,
13    /// The provided [`PtrCfg`](crate::config::PtrCfg) would result in UB if used with
14    /// provided pointer.
15    UnsafeConfig,
16}
17
18impl Display for PackedPtrError {
19    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
20        match *self {
21            Self::UnalignedAddress => f.write_str("unaligned address"),
22            Self::DataOverflow => f.write_str("data too large"),
23            Self::UnsafeConfig => f.write_str("unsafe config"),
24        }
25    }
26}
27
28#[cfg(feature = "std")]
29impl std::error::Error for PackedPtrError {}