Function utf8_supported

Source
pub fn utf8_supported() -> Utf8Support
Expand description

Determine the UTF-8 support of the current locale.

Examples found in repository?
examples/is_utf8.rs (line 4)
3pub fn main() {
4    match utf8_supported::utf8_supported() {
5        utf8_supported::Utf8Support::UTF8 => println!("is_utf8: UTF-8 ✅"),
6        utf8_supported::Utf8Support::ASCII => println!("is_utf8: ASCII"),
7        utf8_supported::Utf8Support::Latin1 => std::io::stdout()
8            .write_all(b"is_utf8: Latin 1: \xb2\xb3\xb9\n")
9            .unwrap(),
10        utf8_supported::Utf8Support::Other => println!("is_utf8: Other"),
11        utf8_supported::Utf8Support::Unknown => println!("is_utf8: Unknown"),
12    }
13}
More examples
Hide additional examples
examples/run_subprocess.rs (line 10)
4pub fn main() {
5    let mut cmd = Command::new(std::env::args().nth(1).expect("No command provided"));
6
7    #[cfg(windows)]
8    let handle = utf8_supported::set_console_utf8().unwrap_or_default();
9
10    let support = utf8_supported::utf8_supported();
11    if support == utf8_supported::Utf8Support::UTF8 {
12        println!("run_subprocess: UTF-8 supported ({support:?})");
13    } else {
14        #[cfg(unix)]
15        {
16            println!("run_subprocess: Setting C locale ({support:?})");
17            cmd.set_c_locale();
18        }
19    }
20    let output = cmd.output().expect("failed to run command");
21    println!("{}", String::from_utf8_lossy(&output.stdout));
22}