Macro ucs2::ucs2_cstr

source ·
macro_rules! ucs2_cstr {
    ($s:literal) => { ... };
}
Expand description

Encode a string as UCS-2 with a trailing null character.

The encoding is done at compile time, so the result can be used in a const item. The type returned by the macro is a [u16; N] array; to avoid having to specify what N is in a const item, take a reference and store it as &[u16].

§Example

use ucs2::ucs2_cstr;

const S: &[u16] = &ucs2_cstr!("abc");
assert_eq!(S, [97, 98, 99, 0]);