Skip to main content

encode

Function encode 

Source
pub fn encode(text: &str, target: TargetEncoding) -> Result<Vec<u8>, ForgeError>
Expand description

Encode text into target. BOMs for utf-8-bom / utf-16le / utf-16be are prepended manually — encoding_rs never emits them.

Fails instead of writing mojibake: a UTF-16LE target whose content begins with U+0000 is refused (the output would begin FF FE 00 00, which the detector reads back as the UTF-32LE BOM), and GB18030 refuses content containing U+E5E5 — the single Unicode scalar the WHATWG gb18030 encoder cannot map (encoding_rs would silently write the literal text &#58853;).