jabba_lib/jos.rs
1//! connection to the operating system
2
3use std::env;
4
5/// Returns the short name of the underlying operating system.
6///
7/// Posible values are listed here: [https://doc.rust-lang.org/std/env/consts/constant.OS.html](https://doc.rust-lang.org/std/env/consts/constant.OS.html)
8///
9/// # Examples
10///
11/// ```
12/// let name = jabba_lib::jos::get_operating_system_name();
13/// ```
14pub fn get_operating_system_name() -> &'static str {
15 env::consts::OS
16}
17
18/// Returns `true` if the operating system is Linux.
19///
20/// # Examples
21///
22/// ```
23/// let are_we_on_linux = jabba_lib::jos::is_linux();
24/// ```
25pub fn is_linux() -> bool {
26 get_operating_system_name() == "linux"
27}
28
29/// Returns `true` if the operating system is Windows.
30///
31/// # Examples
32///
33/// ```
34/// let are_we_on_windows = jabba_lib::jos::is_windows();
35/// ```
36pub fn is_windows() -> bool {
37 get_operating_system_name() == "windows"
38}
39
40// ==========================================================================
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45
46 #[test]
47 fn get_operating_system_name_test() {
48 assert!(get_operating_system_name().len() > 0);
49 }
50
51 #[test]
52 fn is_linux_test() {
53 assert!(is_linux() != is_windows());
54 }
55
56 #[test]
57 fn is_windows_test() {
58 assert!(is_windows() != is_linux());
59 }
60}