str_array!() { /* proc-macro */ }
Expand description
Procedural macro proc_strarray::str_array!
creates const u8 array
from str or byte str literal.
§Usage
// without specified length
proc_strarray::str_array!(RESULT, "str literal");
// with specified length
proc_strarray::str_array!(RESULT2, "string", 6);
§Arguments
- name of created array
- str or byte str literal
- (optional) expected length of str literal. Length is only used for length check. It will not trim or extend an array.
§Example
// This code will create const array of u8 named STRU from
// content of "stru" str literal.
use proc_strarray::str_array;
// case 1: automatically determine array length.
str_array!(STRU, "stru");
// check if newly created array have length 4 and first character is 's'
assert_eq!(STRU.len(), 4);
assert_eq!(STRU[0], 's' as u8);
// case 2: manually specify expected array length
str_array!(STRU_len, "stru", 4);
assert_eq!(STRU_len.len(), 4);
// case 3: bytestr
str_array!(STRU_byte, b"stru", 4);
assert_eq!(STRU_byte.len(), 4);