Expand description
Provides a macro_rules for making utf-16 literals.
Outputs are arrays of the correct size. Prefix the macro with &
to make
slices.
use utf16_lit::{utf16, utf16_null};
const EXAMPLE: &[u16] = &utf16!("example");
const EXAMPLE_NULL: &[u16] = &utf16_null!("example");
fn main() {
let v: Vec<u16> = "example".encode_utf16().collect();
assert_eq!(v, EXAMPLE);
let v: Vec<u16> = "example".encode_utf16().chain(Some(0)).collect();
assert_eq!(v, EXAMPLE_NULL);
let v: Vec<u16> = "example\0".encode_utf16().collect();
assert_eq!(v, EXAMPLE_NULL);
// You don't even need to assign the output to a const.
assert_eq!(utf16!("This works")[0], 'T' as u8 as u16);
}
Macrosยง
- Turns a string literal into a
u16
array literal ([u16; N]
). - Turns a string literal into a
u16
array literal ([u16; N]
) with a trailing0
.