macro_rules! encode { (utf8, $s: expr) => { ... }; (utf16, $s: expr) => { ... }; }
Expand description
Encode a string slice with a specified encoding.
Supported encodings:
- utf8
- utf16
§Examples
use const_str::encode;
const S: &str = "hello你好";
const S_UTF8: &[u8] = encode!(utf8, S);
assert_eq!(S_UTF8, [104, 101, 108, 108, 111, 228, 189, 160, 229, 165, 189]);
const S_UTF16: &[u16] = encode!(utf16, S);
assert_eq!(S_UTF16, [104, 101, 108, 108, 111, 20320, 22909]);