pub trait ToHexExt {
    // Required methods
    fn encode_hex(&self) -> String;
    fn encode_hex_upper(&self) -> String;
    fn encode_hex_with_prefix(&self) -> String;
    fn encode_hex_upper_with_prefix(&self) -> String;
}
Available on crate feature alloc only.
Expand description

Encoding values as hex string.

This trait is implemented for all T which implement AsRef<[u8]>. This includes String, str, Vec<u8> and [u8].

§Examples

use const_hex::ToHexExt;

assert_eq!("Hello world!".encode_hex(), "48656c6c6f20776f726c6421");
assert_eq!("Hello world!".encode_hex_upper(), "48656C6C6F20776F726C6421");
assert_eq!("Hello world!".encode_hex_with_prefix(), "0x48656c6c6f20776f726c6421");
assert_eq!("Hello world!".encode_hex_upper_with_prefix(), "0x48656C6C6F20776F726C6421");

Required Methods§

fn encode_hex(&self) -> String

Encode the hex strict representing self into the result. Lower case letters are used (e.g. f9b4ca).

fn encode_hex_upper(&self) -> String

Encode the hex strict representing self into the result. Upper case letters are used (e.g. F9B4CA).

fn encode_hex_with_prefix(&self) -> String

Encode the hex strict representing self into the result with prefix 0x. Lower case letters are used (e.g. 0xf9b4ca).

fn encode_hex_upper_with_prefix(&self) -> String

Encode the hex strict representing self into the result with prefix 0X. Upper case letters are used (e.g. 0xF9B4CA).

Implementors§

§

impl<T> ToHexExt for T
where T: AsRef<[u8]>,