Macro tor_hsservice::internal_prelude::impl_debug_hex

macro_rules! impl_debug_hex {
    { $type:ty $(,)? } => { ... };
    { $type:ident . $($accessor:tt)+ } => { ... };
    { $type:ty, $obtain:expr $(,)? } => { ... };
}
Expand description

Define Debug to print as hex

§Usage

impl_debug_hex! { $type }
impl_debug_hex! { $type . $field_accessor }
impl_debug_hex! { $type , $accessor_fn }

By default, this expects $type to implement AsRef<[u8]>.

Or, you can supply a series of tokens $field_accessor, which will be used like this: self.$field_accessor.as_ref() to get a &[u8].

Or, you can supply $accessor: fn(&$type) -> &[u8].

§Examples

use tor_basic_utils::impl_debug_hex;
#[derive(Default)]
struct FourBytes([u8; 4]);
impl AsRef<[u8]> for FourBytes { fn as_ref(&self) -> &[u8] { &self.0 } }
impl_debug_hex! { FourBytes }

assert_eq!(
    format!("{:?}", FourBytes::default()),
    "FourBytes(00000000)",
);
use tor_basic_utils::impl_debug_hex;
#[derive(Default)]
struct FourBytes([u8; 4]);
impl_debug_hex! { FourBytes .0 }

assert_eq!(
    format!("{:?}", FourBytes::default()),
    "FourBytes(00000000)",
);
use tor_basic_utils::impl_debug_hex;
struct FourBytes([u8; 4]);
impl_debug_hex! { FourBytes, |self_| &self_.0 }

assert_eq!(
    format!("{:?}", FourBytes([1,2,3,4])),
    "FourBytes(01020304)",
)