13 releases (5 stable)

Uses old Rust 2015

2.3.0 May 21, 2021
2.2.0 Sep 16, 2018
2.0.0 May 19, 2017
1.0.0 May 11, 2017
0.4.0 Nov 29, 2015
Download history 14009/week @ 2021-04-10 13712/week @ 2021-04-17 8718/week @ 2021-04-24 6291/week @ 2021-05-01 15465/week @ 2021-05-08 15412/week @ 2021-05-15 15253/week @ 2021-05-22 15431/week @ 2021-05-29 25065/week @ 2021-06-05 16171/week @ 2021-06-12 11624/week @ 2021-06-19 20321/week @ 2021-06-26 21363/week @ 2021-07-03 15073/week @ 2021-07-10 19429/week @ 2021-07-17 14385/week @ 2021-07-24

51,024 downloads per month
Used in 101 crates (14 directly)

MIT license

17KB
462 lines

Rust

os_type

Rust library to detect the operating system type

Usage

Include this into your Cargo.toml:

[dependencies]
os_type="2.2"

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!("I can't tell what system this is.");
  }
}

Right now, the following operating system types can be returned:

  • Unknown
  • Redhat
  • CentOS
  • OSX
  • Ubuntu
  • Debian
  • Arch
  • Manjaro
  • Alpine

If you need support for more OS types, I am looking forward to your 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

~1–1.4MB
~39K SLoC