pub trait ToAddress: Sealed {
// Required methods
fn from_sprout(net: NetworkType, data: [u8; 64]) -> Self;
fn from_sapling(net: NetworkType, data: [u8; 43]) -> Self;
fn from_unified(net: NetworkType, data: Address) -> Self;
fn from_transparent_p2pkh(net: NetworkType, data: [u8; 20]) -> Self;
fn from_transparent_p2sh(net: NetworkType, data: [u8; 20]) -> Self;
fn from_tex(net: NetworkType, data: [u8; 20]) -> Self;
}
Expand description
A helper trait for converting another type into a ZcashAddress
.
This trait is sealed and cannot be implemented for types outside this crate. Its
purpose is to move these conversion functions out of the main ZcashAddress
API
documentation, as they are only required when creating addresses (rather than when
parsing addresses, which is a more common occurrence).
§Examples
use zcash_address::{ToAddress, ZcashAddress};
use zcash_protocol::consensus::NetworkType;
#[derive(Debug)]
struct MySapling([u8; 43]);
impl MySapling {
/// Encodes this Sapling address for the given network.
fn encode(&self, net: NetworkType) -> ZcashAddress {
ZcashAddress::from_sapling(net, self.0)
}
}
let addr = MySapling([0; 43]);
let encoded = addr.encode(NetworkType::Main);
assert_eq!(
encoded.to_string(),
"zs1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpq6d8g",
);
Required Methods§
fn from_sprout(net: NetworkType, data: [u8; 64]) -> Self
fn from_sapling(net: NetworkType, data: [u8; 43]) -> Self
fn from_unified(net: NetworkType, data: Address) -> Self
fn from_transparent_p2pkh(net: NetworkType, data: [u8; 20]) -> Self
fn from_transparent_p2sh(net: NetworkType, data: [u8; 20]) -> Self
fn from_tex(net: NetworkType, data: [u8; 20]) -> Self
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.