Remove private fmt_internal function
Just use `fmt::Display::fmt` directly since `fmt_internal` does exactly that. Refactor only, no logic changes.
This commit is contained in:
parent
923ce7402d
commit
1ee989a3af
|
@ -43,7 +43,7 @@ impl fmt::Display for Error {
|
|||
UnrecognizedScript => write!(f, "script is not a p2pkh, p2sh or witness program"),
|
||||
NetworkValidation { required, ref address } => {
|
||||
write!(f, "address ")?;
|
||||
address.fmt_internal(f)?; // Using fmt_internal in order to remove the "Address<NetworkUnchecked>(..)" wrapper
|
||||
fmt::Display::fmt(&address.0, f)?;
|
||||
write!(f, " is not valid on {}", required)
|
||||
}
|
||||
Error::UnknownHrp(ref e) => write_err!(f, "unknown hrp"; e),
|
||||
|
|
|
@ -380,7 +380,7 @@ struct DisplayUnchecked<'a, N: NetworkValidation>(&'a Address<N>);
|
|||
|
||||
#[cfg(feature = "serde")]
|
||||
impl<N: NetworkValidation> fmt::Display for DisplayUnchecked<'_, N> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { self.0.fmt_internal(fmt) }
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(&self.0 .0, fmt) }
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
|
@ -404,11 +404,6 @@ impl<V: NetworkValidation> Address<V> {
|
|||
pub fn as_unchecked(&self) -> &Address<NetworkUnchecked> {
|
||||
unsafe { &*(self as *const Address<V> as *const Address<NetworkUnchecked>) }
|
||||
}
|
||||
|
||||
/// Format the address for the usage by `Debug` and `Display` implementations.
|
||||
fn fmt_internal(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Display::fmt(&self.0, fmt)
|
||||
}
|
||||
}
|
||||
|
||||
/// Methods and functions that can be called only on `Address<NetworkChecked>`.
|
||||
|
@ -759,16 +754,16 @@ impl From<Address> for script::ScriptBuf {
|
|||
// Alternate formatting `{:#}` is used to return uppercase version of bech32 addresses which should
|
||||
// be used in QR codes, see [`Address::to_qr_uri`].
|
||||
impl fmt::Display for Address {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { self.fmt_internal(fmt) }
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(&self.0, fmt) }
|
||||
}
|
||||
|
||||
impl<V: NetworkValidation> fmt::Debug for Address<V> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if V::IS_CHECKED {
|
||||
self.fmt_internal(f)
|
||||
fmt::Display::fmt(&self.0, f)
|
||||
} else {
|
||||
write!(f, "Address<NetworkUnchecked>(")?;
|
||||
self.fmt_internal(f)?;
|
||||
fmt::Display::fmt(&self.0, f)?;
|
||||
write!(f, ")")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue