Expand description
Macros converting character encodings at compile time which reduce runtime processing costs and binary size.
Encoding definitions depend on the encoding_rs crate.
Examples
Fucntion-style macros convert a string literal into encoded bytes array.
const BYTES: &[u8] = encoded::shift_jis!("漢字");
assert_eq!(BYTES, b"\x8a\xbf\x8e\x9a");Can also be used with std::io::Write:
use std::io::{Cursor, Write};
let mut buff = Cursor::new(Vec::new());
buff.write_all(encoded::shift_jis!("漢字"));
assert_eq!(buff.get_ref(), b"\x8a\xbf\x8e\x9a");Compile Errors
Argument must be a literal:
ⓘ
let kanji = "漢字";
const BYTES: &[u8] = encoded::shift_jis!(kanji);
// ^^^^^Any unmappable characters result a compile error:
ⓘ
const BYTES: &[u8] = encoded::shift_jis!("鷗外");
// ^^^^^^Macros
Examples
Examples
Examples
Examples
Examples
Examples
Examples
Examples
Examples
Examples
Examples
Examples
Examples
Examples
Examples
Examples
Examples
Examples
Examples
Examples
Examples
Examples
Examples
Examples
Examples
Examples