Skip to main content

hex_string

Function hex_string 

Source
pub fn hex_string(src: &[u8]) -> String
Available on crate feature alloc only.
Expand description

Encodes src as an owned lowercase hexadecimal string.

Each byte produces two ASCII digits, including leading zeroes. The result has length src.len() * 2, contains no prefix or separators, and owns its storage independently of src. Empty input produces an empty string.

Available with the alloc feature. To reuse a string’s capacity, use hex_append. For caller-provided storage, use hex_encode.

§Panics

Panics if the encoded length cannot be represented or exceeds isize::MAX bytes. Allocation failure follows the allocator’s error handling; it is not returned as an Error.

§Examples

use faster_hex::hex_string;

assert_eq!(hex_string(&[0, 0xab, 0xff]), "00abff");
assert_eq!(hex_string(&[]), "");