utility_cli_rs/types/
slip10.rs1#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
2pub struct BIP32Path(pub slip10::BIP32Path);
3
4impl std::fmt::Display for BIP32Path {
5 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
6 self.0.fmt(f)
7 }
8}
9
10impl std::str::FromStr for BIP32Path {
11 type Err = color_eyre::eyre::Report;
12
13 fn from_str(s: &str) -> Result<Self, Self::Err> {
14 let bip32path = slip10::BIP32Path::from_str(s).map_err(Self::Err::msg)?;
15 Ok(Self(bip32path))
16 }
17}
18
19impl From<BIP32Path> for slip10::BIP32Path {
20 fn from(item: BIP32Path) -> Self {
21 item.0
22 }
23}
24
25impl From<slip10::BIP32Path> for BIP32Path {
26 fn from(item: slip10::BIP32Path) -> Self {
27 Self(item)
28 }
29}
30
31impl serde::ser::Serialize for BIP32Path {
32 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
33 where
34 S: serde::ser::Serializer,
35 {
36 serializer.serialize_str(&self.0.to_string())
37 }
38}
39
40impl<'de> serde::de::Deserialize<'de> for BIP32Path {
41 fn deserialize<D>(deserializer: D) -> Result<BIP32Path, D::Error>
42 where
43 D: serde::de::Deserializer<'de>,
44 {
45 String::deserialize(deserializer)?
46 .parse()
47 .map_err(|err: color_eyre::eyre::Report| serde::de::Error::custom(err.to_string()))
48 }
49}
50
51impl interactive_clap::ToCli for crate::types::slip10::BIP32Path {
52 type CliVariant = crate::types::slip10::BIP32Path;
53}