multiversx_sc_codec/
codec_err_handler.rsuse core::convert::Infallible;
use crate::{DecodeError, EncodeError};
pub trait EncodeErrorHandler: Copy {
type HandledErr: 'static;
fn handle_error(&self, err: EncodeError) -> Self::HandledErr;
}
pub trait DecodeErrorHandler: Copy {
type HandledErr: 'static;
fn handle_error(&self, err: DecodeError) -> Self::HandledErr;
}
impl EncodeErrorHandler for DefaultErrorHandler {
type HandledErr = EncodeError;
#[inline]
fn handle_error(&self, err: EncodeError) -> Self::HandledErr {
err
}
}
#[derive(Clone, Copy)]
pub struct DefaultErrorHandler;
impl DecodeErrorHandler for DefaultErrorHandler {
type HandledErr = DecodeError;
#[inline]
fn handle_error(&self, err: DecodeError) -> Self::HandledErr {
err
}
}
#[derive(Clone, Copy)]
pub struct PanicErrorHandler;
impl EncodeErrorHandler for PanicErrorHandler {
type HandledErr = Infallible;
#[inline]
fn handle_error(&self, err: EncodeError) -> Self::HandledErr {
panic!("Encode error occured: {}", err.message_str())
}
}
impl DecodeErrorHandler for PanicErrorHandler {
type HandledErr = Infallible;
#[inline]
fn handle_error(&self, err: DecodeError) -> Self::HandledErr {
panic!("Decode error occured: {}", err.message_str())
}
}