If you use nightly Rust (starting from 1.28.0-nightly, 2018-05-23), you can include the const_str_as_bytes
function, which turns as_bytes()
into a const
function.
#![feature(const_str_as_bytes)] fn main() { const AAA: &[u8] = stringify!(aaa).as_bytes(); println!("{:?}", AAA);
( Demo )
source share