Merge rust-bitcoin/rust-bitcoin#1596: Implement fmt traits for ScriptBuf

ed6f6d11dd Implement fmt traits for ScriptBuf (Tobin C. Harding)

Pull request description:

  We can improve ergonomics of the `script` module by implementing the `fmt` traits on `ScriptBuf`, trivial because we can call through to the `Script` implementations.

  Fix: #1585

ACKs for top commit:
  Kixunil:
    ACK ed6f6d11dd
  apoelstra:
    ACK ed6f6d11dd

Tree-SHA512: 878a1522af4ed1e10d1d8d60d150e6571008c008b5e5c662c67462f9e09075b4f1fe4e399ed50e98cd7253b6815937c6732cd1ce02b74a5be017d5b8fcdbbd2f
This commit is contained in:
Andrew Poelstra 2023-01-31 14:31:42 +00:00
commit ca902e65f8
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 21 additions and 0 deletions

View File

@ -691,6 +691,27 @@ impl core::str::FromStr for ScriptBuf {
}
}
impl fmt::Display for ScriptBuf {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self.as_script(), f)
}
}
impl fmt::LowerHex for ScriptBuf {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::LowerHex::fmt(self.as_script(), f)
}
}
impl fmt::UpperHex for ScriptBuf {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::UpperHex::fmt(self.as_script(), f)
}
}
/// An object which can be used to construct a script piece by piece.
#[derive(PartialEq, Eq, Clone)]
pub struct Builder(ScriptBuf, Option<opcodes::All>);