elrond_codec/
codec_err_handler.rs1use crate::{DecodeError, EncodeError};
2
3pub trait EncodeErrorHandler: Copy {
4 type HandledErr: 'static;
5
6 fn handle_error(&self, err: EncodeError) -> Self::HandledErr;
7}
8
9pub trait DecodeErrorHandler: Copy {
10 type HandledErr: 'static;
11
12 fn handle_error(&self, err: DecodeError) -> Self::HandledErr;
13}
14
15impl EncodeErrorHandler for DefaultErrorHandler {
16 type HandledErr = EncodeError;
17
18 #[inline]
19 fn handle_error(&self, err: EncodeError) -> Self::HandledErr {
20 err
21 }
22}
23
24#[derive(Clone, Copy)]
26pub struct DefaultErrorHandler;
27
28impl DecodeErrorHandler for DefaultErrorHandler {
29 type HandledErr = DecodeError;
30
31 #[inline]
32 fn handle_error(&self, err: DecodeError) -> Self::HandledErr {
33 err
34 }
35}
36
37#[derive(Clone, Copy)]
39pub struct PanicErrorHandler;
40
41impl EncodeErrorHandler for PanicErrorHandler {
42 type HandledErr = !;
43
44 #[inline]
45 fn handle_error(&self, err: EncodeError) -> Self::HandledErr {
46 panic!("Encode error occured: {}", err.message_str())
47 }
48}
49
50impl DecodeErrorHandler for PanicErrorHandler {
51 type HandledErr = !;
52
53 #[inline]
54 fn handle_error(&self, err: DecodeError) -> Self::HandledErr {
55 panic!("Decode error occured: {}", err.message_str())
56 }
57}