use super::MemoryType;
use core::{fmt, fmt::Display};
#[derive(Debug)]
#[non_exhaustive]
pub enum MemoryError {
OutOfBoundsAllocation,
OutOfBoundsGrowth,
OutOfBoundsAccess,
InvalidMemoryType,
InvalidSubtype {
ty: MemoryType,
other: MemoryType,
},
TooManyMemories,
InvalidStaticBufferSize,
}
#[cfg(feature = "std")]
impl std::error::Error for MemoryError {}
impl Display for MemoryError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::OutOfBoundsAllocation => {
write!(f, "out of bounds memory allocation")
}
Self::OutOfBoundsGrowth => {
write!(f, "out of bounds memory growth")
}
Self::OutOfBoundsAccess => {
write!(f, "out of bounds memory access")
}
Self::InvalidMemoryType => {
write!(f, "tried to create an invalid virtual memory type")
}
Self::InvalidSubtype { ty, other } => {
write!(f, "memory type {ty:?} is not a subtype of {other:?}",)
}
Self::TooManyMemories => {
write!(f, "too many memories")
}
Self::InvalidStaticBufferSize => {
write!(f, "tried to use too small static buffer")
}
}
}
}