use core::ops::{ControlFlow, FromResidual, Try};
#[derive(Debug, Clone)]
#[repr(u8)]
pub enum ErrorCode {
ArchivingError = 255,
UnarchivingError = 254,
DeserializationError = 253,
PhoenixTransactionError = 252,
MoonlightTransactionError = 251,
ContractCallError = 250,
Ok = 0,
}
impl Try for ErrorCode {
type Output = ErrorCode;
type Residual = ErrorCode;
fn from_output(_: Self::Output) -> Self {
ErrorCode::Ok
}
fn branch(self) -> ControlFlow<Self::Residual, Self::Output> {
match self {
ErrorCode::Ok => ControlFlow::Continue(ErrorCode::Ok),
_ => ControlFlow::Break(self),
}
}
}
impl FromResidual<ErrorCode> for ErrorCode {
fn from_residual(residual: ErrorCode) -> Self {
residual }
}
impl FromResidual<Result<core::convert::Infallible, ErrorCode>> for ErrorCode {
fn from_residual(
residual: Result<core::convert::Infallible, ErrorCode>,
) -> Self {
match residual {
Err(e) => e,
_ => unreachable!(),
}
}
}