diff options
Diffstat (limited to 'src/hdk')
| -rw-r--r-- | src/hdk/path.rs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/hdk/path.rs b/src/hdk/path.rs index f67446a..3d7c0a3 100644 --- a/src/hdk/path.rs +++ b/src/hdk/path.rs @@ -1,7 +1,10 @@ //! Module implementing parsing for BIP-0032 HD paths used for key derivation. use anyhow::{anyhow, Context as _, Result}; -use std::str::FromStr; +use std::{ + fmt::{self, Display, Formatter}, + str::FromStr, +}; /// A parsed hierarchical derivation path. #[derive(Debug)] @@ -16,6 +19,17 @@ impl Path { } } +impl Display for Path { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + f.write_str("m")?; + for component in self.components() { + write!(f, "/{}", component)?; + } + + Ok(()) + } +} + impl FromStr for Path { type Err = anyhow::Error; @@ -40,6 +54,15 @@ pub enum Component { Normal(u32), } +impl Display for Component { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + match self { + Self::Hardened(value) => write!(f, "{}'", value), + Self::Normal(value) => write!(f, "{}", value), + } + } +} + impl FromStr for Component { type Err = anyhow::Error; |
