1use std::fmt;
4
5#[derive(Debug)]
7pub enum Error {
8 Mnemonic(bip39::Error),
10 InvalidWordCount(usize),
12}
13
14impl fmt::Display for Error {
15 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16 match self {
17 Self::Mnemonic(e) => write!(f, "mnemonic error: {e}"),
18 Self::InvalidWordCount(n) => {
19 write!(f, "invalid word count {n}, must be 12, 15, 18, 21, or 24")
20 }
21 }
22 }
23}
24
25impl std::error::Error for Error {
26 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
27 match self {
28 Self::Mnemonic(e) => Some(e),
29 Self::InvalidWordCount(_) => None,
30 }
31 }
32}
33
34impl From<bip39::Error> for Error {
35 fn from(err: bip39::Error) -> Self {
36 Self::Mnemonic(err)
37 }
38}