From a209836a99e23d77562b032308d3973c0fd4f554 Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Wed, 9 Feb 2022 09:22:07 +0000 Subject: [PATCH] Implement LowerHex and Display for Message Implement `fmt::LowerHex` for `Message`. Implement `Display` by calling `LowerHex`. Resolves: #251 --- src/lib.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index c007c98..9566339 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -308,6 +308,21 @@ impl From for Message { } } +impl fmt::LowerHex for Message { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + for byte in self.0.iter() { + write!(f, "{:02x}", byte)?; + } + Ok(()) + } +} + +impl fmt::Display for Message { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::LowerHex::fmt(self, f) + } +} + /// An ECDSA error #[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Debug)] pub enum Error {