Macro wchar::wchz[][src]

wchz!() { /* proc-macro */ }
Expand description

Generate a C-style nul-terminated UTF-16 or UTF-32 wide string from a string literal.

Validations are made that the given string does not contain nul characters.

The generated output takes the form of a slice of wide characters, with a nul-terminator as the last wide character.

The first argument is the output character type, if no type is specified the platform native wchar_t will be used.

Examples

Basic usage (platform native):

const WIDE: &[wchar_t] = wchz!("foo");

UTF-16 usage:

let wide_str = wchz!(u16, "bar");
let expected = &[0x0062, 0x0061, 0x0072, 0x0000];

assert_eq!(wide_str, expected);

UTF-32 usage:

let wide_str = wchz!(u32, "bar");
let expected = &[0x0000_0062, 0x0000_0061, 0x0000_0072, 0x0000_0000];

assert_eq!(wide_str, expected);