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:
Tobin C. Harding 2023-12-05 09:12:23 +11:00
parent 923ce7402d
commit 1ee989a3af
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
2 changed files with 5 additions and 10 deletions

View File

@ -43,7 +43,7 @@ impl fmt::Display for Error {
UnrecognizedScript => write!(f, "script is not a p2pkh, p2sh or witness program"), UnrecognizedScript => write!(f, "script is not a p2pkh, p2sh or witness program"),
NetworkValidation { required, ref address } => { NetworkValidation { required, ref address } => {
write!(f, "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) write!(f, " is not valid on {}", required)
} }
Error::UnknownHrp(ref e) => write_err!(f, "unknown hrp"; e), Error::UnknownHrp(ref e) => write_err!(f, "unknown hrp"; e),

View File

@ -380,7 +380,7 @@ struct DisplayUnchecked<'a, N: NetworkValidation>(&'a Address<N>);
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
impl<N: NetworkValidation> fmt::Display for DisplayUnchecked<'_, N> { 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")] #[cfg(feature = "serde")]
@ -404,11 +404,6 @@ impl<V: NetworkValidation> Address<V> {
pub fn as_unchecked(&self) -> &Address<NetworkUnchecked> { pub fn as_unchecked(&self) -> &Address<NetworkUnchecked> {
unsafe { &*(self as *const Address<V> as *const 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>`. /// 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 // Alternate formatting `{:#}` is used to return uppercase version of bech32 addresses which should
// be used in QR codes, see [`Address::to_qr_uri`]. // be used in QR codes, see [`Address::to_qr_uri`].
impl fmt::Display for Address { 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> { impl<V: NetworkValidation> fmt::Debug for Address<V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if V::IS_CHECKED { if V::IS_CHECKED {
self.fmt_internal(f) fmt::Display::fmt(&self.0, f)
} else { } else {
write!(f, "Address<NetworkUnchecked>(")?; write!(f, "Address<NetworkUnchecked>(")?;
self.fmt_internal(f)?; fmt::Display::fmt(&self.0, f)?;
write!(f, ")") write!(f, ")")
} }
} }