Aim: convert string "1A2B3344"
to hex array [1Au8, 2Bu8, 33u8, 44u8]
at compile time, and that string may be stored in one file.
For now, hex
crate and hex-literal
crate provide the functionality to convert hex string to hex array. However, these two crates can't achieve my goal because:
-
hex
crate provides decode by hex::decode function, which is not aconst fn
, so we can't do it at compile time. -
hex-literal
crate provides decode by hex macro, which only accepts string literal, so I can't do something like
const hex_array: &[u8] = {
let hex_string = include_str!("path/to/hex_file");
hex_literal::hex!(hex_string)
}