16 releases (8 stable)

Uses old Rust 2015

2.6.0 Sep 29, 2022
2.4.0 Dec 15, 2021
2.3.0 May 21, 2021
2.2.0 Sep 16, 2018
0.4.0 Nov 29, 2015

#72 in macOS and iOS APIs

Download history 2433/week @ 2025-09-14 2371/week @ 2025-09-21 2783/week @ 2025-09-28 1999/week @ 2025-10-05 2004/week @ 2025-10-12 2385/week @ 2025-10-19 3529/week @ 2025-10-26 2799/week @ 2025-11-02 2395/week @ 2025-11-09 1758/week @ 2025-11-16 4617/week @ 2025-11-23 4031/week @ 2025-11-30 2169/week @ 2025-12-07 2478/week @ 2025-12-14 1367/week @ 2025-12-21 1547/week @ 2025-12-28

8,159 downloads per month
Used in 23 crates (19 directly)

MIT license

21KB
546 lines

Rust

os_type

Rust library to detect the operating system type, because sometimes you need to know.

Usage

Include this into your Cargo.toml:

[dependencies]
os_type="2.6"

In your code:

extern crate os_type;
let os = os_type::current_platform();
println!("Type: {:?}", os.os_type);
println!("Version: {}", os.version);

Or to provide different handling on different operating systems:

match os_type::current_platform().os_type {
  os_type::OSType::OSX => {
    println!("This is probably an apple laptop!");
  }
  os_type::OSType::Ubuntu => {
    println!("This is running Ubuntu Linux!");
  }
  _ => {
    println!("Unknown Operating System");
  }
}

Using os_type::current_platform().os_type, expect one of these return values:

  • Unknown
  • Redhat
  • CentOS
  • OSX
  • Ubuntu
  • Debian
  • Arch
  • Manjaro
  • Alpine
  • Deepin
  • NixOS
  • Kali

If you need support for more OS types, please consider opening a Pull Request.

Requirements

On Linux based systems this library requires that lsb_release is installed.

Contributing

Bug reports and pull requests are welcome on GitHub. You can find more information about contributing in the CONTRIBUTING.md. This project is intended to be a safe, welcoming space for collaboration and discussion, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

MIT

Dependencies

~2–3MB
~52K SLoC