hd_wallet/
errors.rs

1//! When something goes wrong
2
3use core::fmt;
4
5/// Length of the argument is not valid
6#[derive(Debug)]
7pub struct InvalidLength;
8
9impl fmt::Display for InvalidLength {
10    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11        f.write_str("invalid length")
12    }
13}
14
15impl core::error::Error for InvalidLength {}
16
17/// Value was out of range
18#[derive(Debug)]
19pub struct OutOfRange;
20
21impl fmt::Display for OutOfRange {
22    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23        f.write_str("out of range")
24    }
25}
26
27impl core::error::Error for OutOfRange {}
28
29/// Error returned by parsing child index
30#[derive(Debug)]
31pub enum ParseChildIndexError {
32    /// Indicates that parsing an `u32` integer failed
33    ParseInt(core::num::ParseIntError),
34    /// Parsed index was out of acceptable range
35    IndexNotInRange(OutOfRange),
36}
37
38impl fmt::Display for ParseChildIndexError {
39    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40        match self {
41            Self::ParseInt(_) => f.write_str("child index is not valid u32 integer"),
42            Self::IndexNotInRange(_) => f.write_str("child index is not in acceptable range"),
43        }
44    }
45}
46
47impl core::error::Error for ParseChildIndexError {
48    fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
49        match self {
50            ParseChildIndexError::ParseInt(e) => Some(e),
51            ParseChildIndexError::IndexNotInRange(e) => Some(e),
52        }
53    }
54}