Debian Codegraph @

third_party/rust/whatsys/src/lib.rs

raw
1 //! What kernel version is running?
2 //!
3 //! # Example
4 //!
5 //! ```
6 //! let kernel = whatsys::kernel_version(); // E.g. Some("20.3.0")
7 //! ```
8 //!
9 //! # Supported operating systems
10 //!
11 //! We support the following operating systems:
12 //!
13 //! * Windows
14 //! * macOS
15 //! * Linux
16 //! * Android
17 //!
18 //! # License
19 //!
20 //! MIT. Copyright (c) 2021-2022 Jan-Erik Rediger
21 //!
22 //! Based on:
23 //!
24 //! * [sys-info](https://crates.io/crates/sys-info), [Repository](https://github.com/FillZpp/sys-info-rs), [MIT LICENSE][sys-info-mit]
25 //! * [sysinfo](https://crates.io/crates/sysinfo), [Repository](https://github.com/GuillaumeGomez/sysinfo), [MIT LICENSE][sysinfo-mit]
26 //!
27 //! [sys-info-mit]: https://github.com/FillZpp/sys-info-rs/blob/master/LICENSE
28 //! [sysinfo-mit]: https://github.com/GuillaumeGomez/sysinfo/blob/master/LICENSE
29
30 #![deny(missing_docs)]
31 #![deny(rustdoc::broken_intra_doc_links)]
32
33 cfg_if::cfg_if! {
34 if #[cfg(target_os = "macos")] {
35 mod apple;
36 use apple as system;
37
38 } else if #[cfg(any(target_os = "linux", target_os = "android"))] {
39 mod linux;
40 use linux as system;
41 } else if #[cfg(windows)] {
42 mod windows;
43 use windows as system;
44 } else {
45 mod fallback;
46 use fallback as system;
47 }
48 }
49
50 pub use system::kernel_version;
51
52 #[cfg(target_os = "windows")]
53 pub use system::windows_build_number;
54
55 #[cfg(test)]
56 mod test {
57 use super::*;
58
59 #[test]
60 fn gets_a_version() {
61 assert!(kernel_version().is_some());
62 }
63
64 #[cfg(target_os = "windows")]
65 #[test]
66 fn test_windows_build_number() {
67 let build_number = windows::windows_build_number();
68 assert!(build_number.is_some());
69 }
70 }