use core::alloc::LayoutError;

pub(crate) const OOM_ERR_STR: &str = "out of memory";

#[derive(Debug)]
pub enum Error {
    LayoutError(LayoutError),
    OOM,
}

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 => f.write_str(OOM_ERR_STR),
        }
    }
}

impl core::error::Error for Error {}

impl From<LayoutError> for Error {
    fn from(value: LayoutError) -> Self {
        Error::LayoutError(value)
    }
}
