1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use std::fmt::{Display, Formatter};
use std::num::ParseIntError;

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ParseHashError {
    /// The error returned when the numeric hash string doesn't begin with "0x"
    MissingPrefix,
    /// The error returned when the hexadecimal part of the hash string cannot be parsed
    ParseError(ParseIntError),
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum FromLabelError {
    /// The error returned only when the static label map is bidirectional, and a label
    /// cannot be matched to a hash
    LabelNotFound(String),
    /// The error returned when the hexadecimal part of the hash string cannot be parsed
    ParseError(ParseIntError),
}

impl From<ParseIntError> for ParseHashError {
    fn from(err: ParseIntError) -> Self {
        Self::ParseError(err)
    }
}

impl From<ParseIntError> for FromLabelError {
    fn from(err: ParseIntError) -> Self {
        Self::ParseError(err)
    }
}

impl Display for FromLabelError {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "{:?}", self)
    }
}