zcash_address: Move ZcashAddress::convert into root

Using two separate `impl ZcashAddress` blocks resulted in separate
blocks in the documentation, which is unnecessary.
This commit is contained in:
Jack Grigg 2021-03-13 09:12:52 +13:00 committed by Jack Grigg
parent c7fcee27a2
commit b9f704955a
2 changed files with 13 additions and 13 deletions

View File

@ -1,6 +1,6 @@
use std::{error::Error, fmt};
use crate::{kind::*, AddressKind, Network, ZcashAddress};
use crate::{kind::*, Network};
/// An address type is not supported for conversion.
#[derive(Debug)]
@ -14,20 +14,10 @@ impl fmt::Display for UnsupportedAddress {
impl Error for UnsupportedAddress {}
impl ZcashAddress {
pub fn convert<T: FromAddress>(self) -> Result<T, UnsupportedAddress> {
match self.kind {
AddressKind::Sprout(data) => T::from_sprout(self.net, data),
AddressKind::Sapling(data) => T::from_sapling(self.net, data),
AddressKind::Orchard(data) => T::from_orchard(self.net, data),
AddressKind::P2pkh(data) => T::from_transparent_p2pkh(self.net, data),
AddressKind::P2sh(data) => T::from_transparent_p2sh(self.net, data),
}
}
}
/// A helper trait for converting a [`ZcashAddress`] into another type.
///
/// [`ZcashAddress`]: crate::ZcashAddress
///
/// # Examples
///
/// ```

View File

@ -70,4 +70,14 @@ impl ZcashAddress {
pub fn try_from_encoded(s: &str) -> Result<Self, ParseError> {
s.parse()
}
pub fn convert<T: FromAddress>(self) -> Result<T, UnsupportedAddress> {
match self.kind {
AddressKind::Sprout(data) => T::from_sprout(self.net, data),
AddressKind::Sapling(data) => T::from_sapling(self.net, data),
AddressKind::Orchard(data) => T::from_orchard(self.net, data),
AddressKind::P2pkh(data) => T::from_transparent_p2pkh(self.net, data),
AddressKind::P2sh(data) => T::from_transparent_p2sh(self.net, data),
}
}
}