diff --git a/sdk/src/derivation_path.rs b/sdk/src/derivation_path.rs index c6ff35b87f..2818c55293 100644 --- a/sdk/src/derivation_path.rs +++ b/sdk/src/derivation_path.rs @@ -1,7 +1,7 @@ use { core::{iter::IntoIterator, slice::Iter}, derivation_path::{ChildIndex, DerivationPath as DerivationPathInner}, - std::{fmt, str::FromStr}, + std::{convert::{Infallible, TryFrom}, fmt, str::FromStr}, thiserror::Error, }; @@ -9,13 +9,21 @@ const ACCOUNT_INDEX: usize = 2; const CHANGE_INDEX: usize = 3; /// Derivation path error. -#[derive(Error, Debug, Clone)] +#[derive(Error, Debug, Clone, PartialEq)] pub enum DerivationPathError { #[error("invalid derivation path: {0}")] InvalidDerivationPath(String), + #[error("infallible")] + Infallible, } -#[derive(PartialEq)] +impl From for DerivationPathError { + fn from(_: Infallible) -> Self { + Self::Infallible + } +} + +#[derive(Clone, PartialEq)] pub struct DerivationPath(DerivationPathInner); impl Default for DerivationPath { @@ -24,6 +32,13 @@ impl Default for DerivationPath { } } +impl TryFrom<&str> for DerivationPath { + type Error = DerivationPathError; + fn try_from(s: &str) -> Result { + Self::from_key_str(s) + } +} + impl DerivationPath { fn new>>(path: P) -> Self { Self(DerivationPathInner::new(path))