use core::fmt;
pub use gear_core_errors::*;
pub type Result<T, E = Error> = core::result::Result<T, E>;
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Error {
SyscallUsage,
Ext(ExtError),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::SyscallUsage => write!(f, "syscall usage error"),
Error::Ext(e) => write!(f, "{}", e),
}
}
}
impl From<ExtError> for Error {
fn from(err: ExtError) -> Self {
Error::Ext(err)
}
}
#[must_use]
#[repr(transparent)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct SyscallError(pub(crate) u32);
impl From<SyscallError> for Result<()> {
fn from(value: SyscallError) -> Self {
match value.0 {
0 => Ok(()),
code => Err(ExtError::from_u32(code)
.unwrap_or(ExtError::Unsupported)
.into()),
}
}
}
impl SyscallError {
pub fn into_result(self) -> Result<()> {
self.into()
}
}