Skip to main content

set_default_encoding_by_label

Function set_default_encoding_by_label 

Source
pub fn set_default_encoding_by_label(label: &str) -> Option<&'static Encoding>
Expand description

Sets the global encoding from a label, the way a configuration file names it.

Accepts every label the WHATWG Encoding Standard defines, so "windows-1251", "cp1251" and "cyrillic" all resolve to the same encoding, case and surrounding whitespace ignored. That is what lets a plugin read the encoding from the server’s own configuration instead of compiling it in.

Returns the encoding that was set, or None when the label matches nothing — in which case the current encoding is left alone, and the caller should say so rather than silently run in the wrong encoding.

let chosen = set_default_encoding_by_label("windows-1254");
assert_eq!(chosen.map(Encoding::name), Some("windows-1254"));
assert!(set_default_encoding_by_label("not-an-encoding").is_none());