From 739e13dbd819cfb23cbb9b538870a2d373b48ad4 Mon Sep 17 00:00:00 2001 From: David Lutterkort Date: Thu, 7 Apr 2022 17:27:00 -0700 Subject: [PATCH] Make debug output for Bytes hex strings (0xdeadbeef) --- src/types/bytes.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/types/bytes.rs b/src/types/bytes.rs index dedffe51..830322d7 100644 --- a/src/types/bytes.rs +++ b/src/types/bytes.rs @@ -5,7 +5,7 @@ use serde::{ use std::fmt; /// Raw bytes wrapper -#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] +#[derive(Clone, Default, PartialEq, Eq, Hash)] pub struct Bytes(pub Vec); impl>> From for Bytes { @@ -34,6 +34,13 @@ impl<'a> Deserialize<'a> for Bytes { } } +impl fmt::Debug for Bytes { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let serialized = format!("0x{}", hex::encode(&self.0)); + f.debug_tuple("Bytes").field(&serialized).finish() + } +} + struct BytesVisitor; impl<'a> Visitor<'a> for BytesVisitor {