Macro const_str::encode_z

source ·
macro_rules! encode_z {
    (utf8, $s: expr) => { ... };
    (utf16, $s: expr) => { ... };
}
Expand description

Encode a string slice with a specified encoding and append a nul character.

The provided data should not contain any nul bytes in it.

See also const_str::encode!

§Examples

use const_str::encode_z;

const S: &str = "hello你好";

const S_UTF8_Z: &[u8] = encode_z!(utf8, S);
assert_eq!(S_UTF8_Z, [104, 101, 108, 108, 111, 228, 189, 160, 229, 165, 189, 0]);

const S_UTF16_Z: &[u16] = encode_z!(utf16, S);
assert_eq!(S_UTF16_Z, [104, 101, 108, 108, 111, 20320, 22909, 0]);