1use core::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
25#[cfg(feature = "std")]
26impl std::error::Error for Error {
27 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
28 match self {
29 Self::Mnemonic(e) => Some(e),
30 Self::InvalidWordCount(_) => None,
31 }
32 }
33}
34
35impl From<bip39::Error> for Error {
36 fn from(err: bip39::Error) -> Self {
37 Self::Mnemonic(err)
38 }
39}