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