Skip to content

hex

Hexadecimal encoding and decoding with typed errors.

Decoding accepts either case and rejects anything that is not pairs of hex digits, so trim whitespace and strip 0x prefixes before calling it.

Cargo feature hex (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features hex

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.5", default-features = false, features = ["hex"] }

Import path: helpers4::hex.

ItemWhat it does
decodeDecodes a hexadecimal string (either case) into bytes.
decode_arrayDecodes a hexadecimal string into a fixed-size array, e.g.
decode_to_sliceDecodes a hexadecimal string into out, which must be exactly half as long as the string.
encodeEncodes bytes as lowercase hexadecimal.
encode_upperEncodes bytes as uppercase hexadecimal.

Documented on the page of the helper that returns them.

TypeReturned by
DecodeErrordecode, decode_array, decode_to_slice