Crate hex
Encoding and decoding hex strings.
For most cases, you can simply use the decode, encode and
encode_upper functions. If you need a bit more control, use the traits
ToHex and FromHex instead.
Example
# #[cfg(not(feature = "alloc"))]
# let mut output = [0; 0x18];
#
# #[cfg(not(feature = "alloc"))]
# hex::encode_to_slice(b"Hello world!", &mut output).unwrap();
#
# #[cfg(not(feature = "alloc"))]
# let hex_string = ::core::str::from_utf8(&output).unwrap();
#
# #[cfg(feature = "alloc")]
let hex_string = hex::encode("Hello world!");
println!("{}", hex_string); // Prints "48656c6c6f20776f726c6421"
# assert_eq!(hex_string, "48656c6c6f20776f726c6421");
Modules
-
serde
Hex encoding with
serde.
Enums
-
FromHexError
The error type for decoding a hex string into
Vec<u8>or[u8; N].
Traits
Functions
- decode Decodes a hex string into raw bytes.
- decode_to_slice Decode a hex string into a mutable bytes slice.
- deserialize Deserializes a hex string into raw bytes.
-
encode
Encodes
dataas hex string using lowercase characters. - encode_to_slice Encodes some bytes into a mutable slice of bytes.
-
encode_upper
Encodes
dataas hex string using uppercase characters. -
serialize
Serializes
dataas hex string using lowercase characters. -
serialize_upper
Serializes
dataas hex string using uppercase characters.