pub fn detect(bytes: &[u8]) -> DetectedEncodingExpand description
Classify raw bytes. Rule-based on purpose — no statistical guessing.
The UTF-32 BOMs (FF FE 00 00 LE / 00 00 FE FF BE) are checked before
the 2-byte UTF-16 BOMs (longest-prefix precedence, as in WHATWG BOM
sniffing). Consequence of that precedence: a file starting FF FE 00 00
is always read as UTF-32LE, even when the bytes would also decode as
UTF-16LE whose first character is U+0000 — the two encodings are
indistinguishable there. To keep such files from ever being created, the
UTF-16LE encoder refuses content that begins with U+0000 (the transcoder
reports encode_error), and malformed UTF-32 payloads still fail the
strict decode loudly (decode_error) instead of being transcoded.