use std::fmt;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug)]
pub enum Error {
Lua(mlua::Error),
DuplicatePermKey(String),
PersistFailed(String),
UnpersistFailed(String),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Lua(e) => write!(f, "mlua error: {}", e),
Error::DuplicatePermKey(k) => {
write!(f, "perm key already registered: '{}'", k)
}
Error::PersistFailed(msg) => write!(f, "eris.persist failed: {}", msg),
Error::UnpersistFailed(msg) => write!(f, "eris.unpersist failed: {}", msg),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Lua(e) => Some(e),
_ => None,
}
}
}
impl From<mlua::Error> for Error {
fn from(e: mlua::Error) -> Self {
Error::Lua(e)
}
}