Unsized constants?

Note that in some cases we want to preserver the array type, so unfortunately a const function which returns &[u8] will not cover all use-cases. Ideally I would like to be able to write something like:

const fn calc_hex_size(data: &str) -> usize { .. }

const fn from_hex<const N: usize>(const data: &str) -> [u8; N]
    // only const arguments can be used in `where` clauses
    where N = calc_hex_size(data)
{ .. }

const arguments were proposed here for a different use-case, but they will fit really nicely here as well.

cc @gnzlbg

1 Like