Skip to main content

Module hex

Module hex 

Expand description

Hexadecimal encoding and decoding utilities.

Use crate::fmt::hex to borrow bytes as a configurable Hex view. The view supports deferred formatting, owned text output, and writing into existing strings, byte buffers, or slices. Encoding defaults to lowercase without a prefix and works with no_std + alloc.

The byte/pair helpers are also useful in URI percent-encoding and decoding. Use decode to decode into a vector or fixed-size array.

Structs§

BufferTooSmall
The destination cannot hold the complete hex encoding.
Format
Shared hex representation for encoding and decoding.
Hex
A borrowed view that encodes bytes as hex digits with optional framing.

Enums§

DecodeError
Invalid hex input or an incompatible output size. Indices are byte offsets in the original input, including prefix/separators.
DecodeWriteErrorstd
Invalid input or an I/O failure while writing decoded bytes.

Traits§

FromHex
An owned destination for decoded bytes.

Functions§

decode
Decode compact hex into an inferred vector or fixed-size array.
decode_append
Append decoded bytes to a collection, returning the number supplied to it.
decode_into
Decode into an existing slice-like buffer, returning its written portion.
decode_pair
Decode a %XX-style hex pair to its byte value, or None if either nibble is not a valid hex digit.
decode_upper_pair
Decode two uppercase ASCII hex digits to one byte.
decode_writestd
Decode into a byte writer without allocating an intermediate vector.
encode_byte_lower
Encode one byte as two lowercase ASCII hex digits.
encode_byte_upper
Encode one byte as two uppercase ASCII hex digits.
nibble
ASCII hex digit → 0..=15, None for non-hex bytes.
upper_nibble
Uppercase ASCII hex digit to 0..=15.