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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use core;
use std::{error, fmt, io};
#[derive(Debug)]
pub enum Error {
MnemonicError(String),
KeyGenerationError(String),
}
impl From<core::Error> for Error {
fn from(err: core::Error) -> Self {
Error::MnemonicError(err.to_string())
}
}
impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
Error::MnemonicError(err.to_string())
}
}
impl<'a> From<&'a str> for Error {
fn from(err: &str) -> Self {
Error::MnemonicError(err.to_string())
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::MnemonicError(ref str) => write!(f, "Mnemonic generation error: {}", str),
Error::KeyGenerationError(ref str) => write!(f, "BIP32 generation error: {}", str),
}
}
}
impl error::Error for Error {
fn description(&self) -> &str {
"Mnemonic generation error"
}
fn cause(&self) -> Option<&error::Error> {
match *self {
_ => None,
}
}
}