Merge rust-bitcoin/rust-bitcoin#3841: Remove macro `debug_from_display`

fd8d563b87 Remove macro debug_from_display (Tobin C. Harding)

Pull request description:

  Rust macros, while at times useful, are a maintenance nightmare. And we have been bitten by calling macros from other crates multiple times in the past.

  In a push to just use less macros remove the `debug_from_display` macro and just write the code.

  This is an API breaking change to `internals` but an internal change only to any of the _real_ crates.

ACKs for top commit:
  apoelstra:
    ACK fd8d563b873c87a996d82062285169e16e3f0c13; successfully ran local tests; this is a great change

Tree-SHA512: 26faa6645d010c1b5873d584c36d0fc52b73553d88be3226937431210ccc2479548757593b8a151936e9fa280cb3c604b241511f24ef0aa5cbf3f424d7ecf215
This commit is contained in:
merge-script 2025-01-03 23:01:11 +00:00
commit 192ea44d87
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
4 changed files with 17 additions and 21 deletions

View File

@ -150,4 +150,8 @@ impl fmt::Display for Builder {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(&self.0, f) }
}
internals::debug_from_display!(Builder);
impl fmt::Debug for Builder {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
fmt::Display::fmt(self, f)
}
}

View File

@ -24,7 +24,7 @@ use core::str::FromStr;
use core::{fmt, ops};
use hex::FromHex;
use internals::{debug_from_display, impl_to_hex_from_lower_hex, write_err};
use internals::{impl_to_hex_from_lower_hex, write_err};
use io::{BufRead, Write};
use crate::consensus::encode::{self, Decodable, Encodable};
@ -291,7 +291,12 @@ impl fmt::Display for Magic {
Ok(())
}
}
debug_from_display!(Magic);
impl fmt::Debug for Magic {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
fmt::Display::fmt(self, f)
}
}
impl fmt::LowerHex for Magic {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {

View File

@ -2,21 +2,6 @@
//! Various macros used by the Rust Bitcoin ecosystem.
/// Implements `Debug` by calling through to `Display`.
#[macro_export]
macro_rules! debug_from_display {
($thing:ident) => {
impl core::fmt::Debug for $thing {
fn fmt(
&self,
f: &mut core::fmt::Formatter,
) -> core::result::Result<(), core::fmt::Error> {
core::fmt::Display::fmt(self, f)
}
}
};
}
/// Asserts a boolean expression at compile time.
#[macro_export]
macro_rules! const_assert {

View File

@ -9,8 +9,6 @@
use core::fmt;
use internals::debug_from_display;
#[cfg(feature = "serde")]
use crate::prelude::ToString;
@ -441,7 +439,11 @@ impl From<u8> for Opcode {
fn from(b: u8) -> Opcode { Opcode { code: b } }
}
debug_from_display!(Opcode);
impl fmt::Debug for Opcode {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
fmt::Display::fmt(self, f)
}
}
#[cfg(feature = "serde")]
impl serde::Serialize for Opcode {