Macro wchar::wch [−][src]
wch!() { /* proc-macro */ }
Expand description
Generate a UTF-16 or UTF-32 wide string from a string literal.
The generated output takes the form of a slice of wide characters.
The first argument is the output character type, if no type is specified the
platform native wchar_t
will be used.
Notes
Whilst this macro can be used for C-style nul-terminated wide strings, no
validations are made about internal nul characters. If your strings need to
be nul-terminated it is recommended to use wchz
.
Examples
Basic usage (platform native):
const WIDE: &[wchar_t] = wch!("foo");
UTF-16 usage:
let wide_str = wch!(u16, "foo"); let expected = &[0x0066, 0x006F, 0x006F]; assert_eq!(wide_str, expected);
UTF-32 usage:
let wide_str = wch!(u32, "foo"); let expected = &[0x0000_0066, 0x0000_006F, 0x0000_006F]; assert_eq!(wide_str, expected);