use core::alloc::LayoutError;
pub(crate) const OOM_ERR_STR: &str = "out of memory";
#[derive(Debug)]
pub struct OOMError;
impl core::fmt::Display for OOMError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str(OOM_ERR_STR)
}
}
impl core::error::Error for OOMError {}
#[derive(Debug)]
pub enum Error {
LayoutError(LayoutError),
OOM(OOMError),
}
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Error::LayoutError(e) => core::fmt::Display::fmt(e, f),
Error::OOM(e) => core::fmt::Display::fmt(e, f),
}
}
}
impl core::error::Error for Error {}
impl From<LayoutError> for Error {
fn from(value: LayoutError) -> Self {
Error::LayoutError(value)
}
}
impl From<OOMError> for Error {
fn from(value: OOMError) -> Self {
Error::OOM(value)
}
}