parity_multihash/
errors.rs1use std::{error, fmt};
2
3#[derive(Debug, Copy, Clone, PartialEq, Eq)]
5pub enum EncodeError {
6 UnsupportedType,
8 UnsupportedInputLength,
10}
11
12impl fmt::Display for EncodeError {
13 #[inline]
14 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15 match *self {
16 EncodeError::UnsupportedType => write!(f, "This type is not supported yet"),
17 EncodeError::UnsupportedInputLength => write!(
18 f,
19 "The length of the input for the given hash is not yet supported"
20 ),
21 }
22 }
23}
24
25impl error::Error for EncodeError {}
26
27#[derive(Debug, Copy, Clone, PartialEq, Eq)]
29pub enum DecodeError {
30 BadInputLength,
32 UnknownCode,
34}
35
36impl fmt::Display for DecodeError {
37 #[inline]
38 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39 match *self {
40 DecodeError::BadInputLength => write!(f, "Not matching input length"),
41 DecodeError::UnknownCode => write!(f, "Found unknown code"),
42 }
43 }
44}
45
46impl error::Error for DecodeError {}
47
48#[derive(Debug, Clone, PartialEq, Eq)]
52pub struct DecodeOwnedError {
53 pub error: DecodeError,
55 pub data: Vec<u8>,
57}
58
59impl fmt::Display for DecodeOwnedError {
60 #[inline]
61 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
62 write!(f, "{}", self.error)
63 }
64}
65
66impl error::Error for DecodeOwnedError {}