str_array0!() { /* proc-macro */ }Expand description
Procedural macro proc_strarray::str_array0! creates zero terminated
const u8 array from str or byte str literal.
Macro is same as str_array! but it will append \0 to result.
Optional array length must include terminating \0.
ยงSee also
str_array!: Creates a non-zero terminated const u8 array from a str literal.
// Create const array of u8 named STRU from content of "stru" str literal.
use proc_strarray::str_array0;
// case 1: without specifying length
str_array0!(STRU, "stru");
// check if created array have length 4 + 1 \\0 and first character is 's'
assert_eq!(STRU.len(), 4+1);
assert_eq!(STRU[0], 's' as u8);
assert_eq!(STRU[4], 0);
// case 2: with specifying length
str_array0!(STRU2, "stru", 5);
// check if newly created array have length 5
assert_eq!(STRU.len(), 5);
// case 3: bytestr
str_array0!(STRU_byte, b"stru", 5);
assert_eq!(STRU_byte.len(), 4 + 1);