use alloc::string::String;
use core::fmt;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum LayoutError {
InvalidAlignment(u64),
Overflow,
DuplicateField(String),
MissingPointerLayout,
InvalidTypeSize {
size: u64,
align: u64,
},
}
impl fmt::Display for LayoutError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidAlignment(align) => {
write!(f, "alignment must be a nonzero power of two, got {align}")
}
Self::Overflow => f.write_str("layout calculation exceeds u64::MAX bytes"),
Self::DuplicateField(name) => write!(f, "duplicate field name: {name}"),
Self::MissingPointerLayout => {
f.write_str("pointer size and alignment must be specified")
}
Self::InvalidTypeSize { size, align } => {
write!(
f,
"type size {size} must be nonzero and divisible by alignment {align}"
)
}
}
}
}
impl core::error::Error for LayoutError {}