utf8-supported 1.0.0

Determine the UTF-8 support of the current locale.
Documentation
  • Coverage
  • 64.29%
    9 out of 14 items documented1 out of 7 items with examples
  • Size
  • Source code size: 27.14 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.71 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 23s Average build duration of successful builds.
  • all releases: 18s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • mmastrac/utf8-supported
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • mmastrac

utf8-supported

Crates.io Documentation

A Rust library for determining the UTF-8 support of the current terminal locale.

Example:

use std::io::Write;

match utf8_supported::utf8_supported() {
    utf8_supported::Utf8Support::UTF8 => println!("is_utf8: UTF-8 ✅"),
    utf8_supported::Utf8Support::ASCII => println!("is_utf8: ASCII"),
    utf8_supported::Utf8Support::Latin1 => std::io::stdout()
        .write_all(b"is_utf8: Latin 1: \xb2\xb3\xb9\n")
        .unwrap(),
    utf8_supported::Utf8Support::Other => println!("is_utf8: Other"),
    utf8_supported::Utf8Support::Unknown => println!("is_utf8: Unknown"),
}

This library can also be used to ensure that a child process runs with the C locale:

#[cfg(unix)] 
{
    use std::process::Command;
    use utf8_supported::CommandUtf8Ext;

    let mut cmd = Command::new("ls");
    if utf8_supported::utf8_supported() != utf8_supported::Utf8Support::UTF8 {
        cmd.set_c_locale();
    }
    cmd.output().unwrap();
}