Macro wchar::wchz[][src]

macro_rules! wchz {
    ($ty:ident, $string:literal) => { ... };
    ($string:literal) => { ... };
}

Generate a C-style nul-terminated UTF-16 or UTF-32 wide string from the given 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 specfied the platform native wchar_t will be used.

Examples

Basic example (platform native):

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

UTF-16 example:

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

assert_eq!(wide_str, expected);

UTF-32 example:

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

assert_eq!(wide_str, expected);