hex_conservative

Trait DisplayHex

Source
pub trait DisplayHex: Copy + IsRef {
    type Display: Display + Debug + LowerHex + UpperHex;

    // Required method
    fn as_hex(self) -> Self::Display;

    // Provided methods
    fn to_lower_hex_string(self) -> String { ... }
    fn to_upper_hex_string(self) -> String { ... }
    fn to_hex_string(self, case: Case) -> String { ... }
    fn append_hex_to_string(self, case: Case, string: &mut String) { ... }
    fn hex_reserve_suggestion(self) -> usize { ... }
}
Expand description

Extension trait for types that can be displayed as hex.

Types that have a single, obvious text representation being hex should not implement this trait and simply implement Display instead.

This trait should be generally implemented for references only. We would prefer to use GAT but that is beyond our MSRV. As a lint we require the IsRef trait which is implemented for all references.

Required Associated Types§

Source

type Display: Display + Debug + LowerHex + UpperHex

The type providing fmt::Display implementation.

This is usually a wrapper type holding a reference to Self.

Required Methods§

Source

fn as_hex(self) -> Self::Display

Display Self as a continuous sequence of ASCII hex chars.

Provided Methods§

Source

fn to_lower_hex_string(self) -> String

Available on crate feature alloc only.

Create a lower-hex-encoded string.

A shorthand for to_hex_string(Case::Lower), so that Case doesn’t need to be imported.

This may be faster than .display_hex().to_string() because it uses reserve_suggestion.

Source

fn to_upper_hex_string(self) -> String

Available on crate feature alloc only.

Create an upper-hex-encoded string.

A shorthand for to_hex_string(Case::Upper), so that Case doesn’t need to be imported.

This may be faster than .display_hex().to_string() because it uses reserve_suggestion.

Source

fn to_hex_string(self, case: Case) -> String

Available on crate feature alloc only.

Create a hex-encoded string.

This may be faster than .display_hex().to_string() because it uses reserve_suggestion.

Source

fn append_hex_to_string(self, case: Case, string: &mut String)

Available on crate feature alloc only.

Appends hex-encoded content to an existing String.

This may be faster than write!(string, "{:x}", self.as_hex()) because it uses hex_reserve_sugggestion.

Source

fn hex_reserve_suggestion(self) -> usize

Hints how much bytes to reserve when creating a String.

Implementors that know the number of produced bytes upfront should override this. Defaults to 0.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'a> DisplayHex for &'a Vec<u8>

Available on crate feature alloc only.
Source§

impl<'a> DisplayHex for &'a [u8; 1]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 2]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 3]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 4]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 5]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 6]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 7]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 8]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 9]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 10]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 11]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 12]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 13]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 14]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 15]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 16]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 20]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 32]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 33]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 64]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 65]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 128]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 256]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 512]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 1024]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 2048]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8; 4096]

Source§

type Display = DisplayArray<'a, {$len * 2}>

Source§

fn as_hex(self) -> Self::Display

Source§

impl<'a> DisplayHex for &'a [u8]

Implementors§