Skip to main content

Crate fast_hex_lite

Crate fast_hex_lite 

Source
Expand description

Fast, allocation-free hex encoding/decoding.

  • no_std by default (scalar path)
  • Optional std support
  • Optional simd accelerated decode/validate on supported targets

§API

§Examples

Decode hex → bytes:

use fast_hex_lite::decode_to_slice;

let hex = b"deadbeef";
let mut buf = [0u8; 4];
let n = decode_to_slice(hex, &mut buf).unwrap();
assert_eq!(&buf[..n], &[0xde, 0xad, 0xbe, 0xef]);

Encode bytes → hex (lowercase):

use fast_hex_lite::encode_to_slice;

let src = [0xde, 0xad, 0xbe, 0xef];
let mut out = [0u8; 8];
let n = encode_to_slice(&src, &mut out, true).unwrap();
assert_eq!(&out[..n], b"deadbeef");

Enums§

Error
Errors that can occur during hex encoding or decoding.

Functions§

decode_in_place
Decode hex bytes in-place: buf initially contains ASCII hex; after decoding, the first buf.len() / 2 bytes hold the result.
decode_to_array
Decode exactly N bytes from a hex string of length 2*N.
decode_to_slice
Decode ASCII-hex bytes src_hex into dst.
decoded_len
Returns the number of bytes produced from a hex string of hex_len bytes.
encode_to_slice
Encode bytes into hex (lowercase or uppercase) into the provided output slice.
encoded_len
Returns the required output length (in bytes) for encoding n bytes to hex.