Skip to content

Commit

Permalink
Make debug output for Bytes hex strings (0xdeadbeef)
Browse files Browse the repository at this point in the history
  • Loading branch information
lutter committed Apr 8, 2022
1 parent 2760dbd commit 739e13d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/types/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>);

impl<T: Into<Vec<u8>>> From<T> for Bytes {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 739e13d

Please sign in to comment.