zcash_address: Document ZcashAddress::convert

This commit is contained in:
Jack Grigg 2021-03-13 10:42:56 +13:00 committed by Jack Grigg
parent b9f704955a
commit ff07eeaabb
1 changed files with 12 additions and 0 deletions

View File

@ -71,6 +71,18 @@ impl ZcashAddress {
s.parse() s.parse()
} }
/// Converts this address into another type.
///
/// `convert` can convert into any type that implements the [`FromAddress`] trait.
/// This enables `ZcashAddress` to be used as a common parsing and serialization
/// interface for Zcash addresses, while delegating operations on those addresses
/// (such as constructing transactions) to downstream crates.
///
/// If you want to get the encoded string for this address, use the [`Display`]
/// implementation instead via [`address.to_string()`].
///
/// [`Display`]: std::fmt::Display
/// [`address.to_string()`]: std::string::ToString
pub fn convert<T: FromAddress>(self) -> Result<T, UnsupportedAddress> { pub fn convert<T: FromAddress>(self) -> Result<T, UnsupportedAddress> {
match self.kind { match self.kind {
AddressKind::Sprout(data) => T::from_sprout(self.net, data), AddressKind::Sprout(data) => T::from_sprout(self.net, data),