Skip to main content

hex

Function hex 

pub fn hex<T>(bytes: &T) -> Hex<'_>
where T: AsRef<[u8]> + ?Sized,
Expand description

Borrow bytes as contiguous lowercase hexadecimal without a prefix.

Creating and configuring the view does not allocate. Use its Hex methods to select case/prefix, create owned output, or encode into an existing destination. Formatting with :x / :X selects lowercase / uppercase; :#x / :#X also adds 0x, independently of the view’s configuration.

use rama_utils::fmt::hex;

let view = hex(&[0x00, 0xab]);
assert_eq!(view.to_string(), "00ab");
assert_eq!(format!("{view:#X}"), "0x00AB");
assert_eq!(hex("Hi").to_vec(), b"4869");