From ed6f6d11dd5d84e65630c48564cfb442a181900b Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 27 Jan 2023 08:53:20 +1100 Subject: [PATCH] Implement fmt traits for ScriptBuf 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. --- bitcoin/src/blockdata/script.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/bitcoin/src/blockdata/script.rs b/bitcoin/src/blockdata/script.rs index dc7bfff9..910082b1 100644 --- a/bitcoin/src/blockdata/script.rs +++ b/bitcoin/src/blockdata/script.rs @@ -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);