libmacchina/
lib.rs

1use cfg_if::cfg_if;
2
3cfg_if! {
4    if #[cfg(all(target_os = "linux", feature = "openwrt"))] {
5        mod extra;
6        mod openwrt;
7
8        pub type BatteryReadout = openwrt::OpenWrtBatteryReadout;
9        pub type KernelReadout = openwrt::OpenWrtKernelReadout;
10        pub type MemoryReadout = openwrt::OpenWrtMemoryReadout;
11        pub type GeneralReadout = openwrt::OpenWrtGeneralReadout;
12        pub type ProductReadout = openwrt::OpenWrtProductReadout;
13        pub type PackageReadout = openwrt::OpenWrtPackageReadout;
14        pub type NetworkReadout = openwrt::OpenWrtNetworkReadout;
15    } else if #[cfg(all(target_os = "linux", not(feature = "openwrt")))] {
16        mod extra;
17        mod linux;
18        mod winman;
19
20        pub type BatteryReadout = linux::LinuxBatteryReadout;
21        pub type KernelReadout = linux::LinuxKernelReadout;
22        pub type MemoryReadout = linux::LinuxMemoryReadout;
23        pub type GeneralReadout = linux::LinuxGeneralReadout;
24        pub type ProductReadout = linux::LinuxProductReadout;
25        pub type PackageReadout = linux::LinuxPackageReadout;
26        pub type NetworkReadout = linux::LinuxNetworkReadout;
27    } else if #[cfg(target_os = "macos")] {
28        mod extra;
29        mod macos;
30
31        pub type BatteryReadout = macos::MacOSBatteryReadout;
32        pub type KernelReadout = macos::MacOSKernelReadout;
33        pub type MemoryReadout = macos::MacOSMemoryReadout;
34        pub type GeneralReadout = macos::MacOSGeneralReadout;
35        pub type ProductReadout = macos::MacOSProductReadout;
36        pub type PackageReadout = macos::MacOSPackageReadout;
37        pub type NetworkReadout = macos::MacOSNetworkReadout;
38    } else if #[cfg(target_os = "netbsd")] {
39        mod extra;
40        mod netbsd;
41        mod winman;
42        pub mod dirs;
43
44        pub type BatteryReadout = netbsd::NetBSDBatteryReadout;
45        pub type KernelReadout = netbsd::NetBSDKernelReadout;
46        pub type MemoryReadout = netbsd::NetBSDMemoryReadout;
47        pub type GeneralReadout = netbsd::NetBSDGeneralReadout;
48        pub type ProductReadout = netbsd::NetBSDProductReadout;
49        pub type PackageReadout = netbsd::NetBSDPackageReadout;
50        pub type NetworkReadout = netbsd::NetBSDNetworkReadout;
51    } else if #[cfg(target_os = "windows")] {
52        mod windows;
53
54        pub type BatteryReadout = windows::WindowsBatteryReadout;
55        pub type KernelReadout = windows::WindowsKernelReadout;
56        pub type MemoryReadout = windows::WindowsMemoryReadout;
57        pub type GeneralReadout = windows::WindowsGeneralReadout;
58        pub type ProductReadout = windows::WindowsProductReadout;
59        pub type PackageReadout = windows::WindowsPackageReadout;
60        pub type NetworkReadout = windows::WindowsNetworkReadout;
61    } else if #[cfg(target_os = "android")] {
62        mod android;
63        mod extra;
64
65        pub type BatteryReadout = android::AndroidBatteryReadout;
66        pub type KernelReadout = android::AndroidKernelReadout;
67        pub type MemoryReadout = android::AndroidMemoryReadout;
68        pub type GeneralReadout = android::AndroidGeneralReadout;
69        pub type ProductReadout = android::AndroidProductReadout;
70        pub type PackageReadout = android::AndroidPackageReadout;
71        pub type NetworkReadout = android::AndroidNetworkReadout;
72    } else if #[cfg(target_os = "freebsd")] {
73        mod extra;
74        mod freebsd;
75        mod winman;
76
77        pub type BatteryReadout = freebsd::FreeBSDBatteryReadout;
78        pub type KernelReadout = freebsd::FreeBSDKernelReadout;
79        pub type MemoryReadout = freebsd::FreeBSDMemoryReadout;
80        pub type GeneralReadout = freebsd::FreeBSDGeneralReadout;
81        pub type ProductReadout = freebsd::FreeBSDProductReadout;
82        pub type PackageReadout = freebsd::FreeBSDPackageReadout;
83        pub type NetworkReadout = freebsd::FreeBSDNetworkReadout;
84    } else {
85        compiler_error!("This platform is currently not supported by libmacchina.");
86    }
87}
88
89pub struct Readouts {
90    pub battery: BatteryReadout,
91    pub kernel: KernelReadout,
92    pub memory: MemoryReadout,
93    pub general: GeneralReadout,
94    pub product: ProductReadout,
95    pub packages: PackageReadout,
96    pub network: NetworkReadout,
97}
98
99#[cfg(feature = "version")]
100pub fn version() -> &'static str {
101    if let Some(git_sha) = option_env!("VERGEN_GIT_SHA_SHORT") {
102        Box::leak(format!("{} ({})", env!("CARGO_PKG_VERSION"), git_sha).into_boxed_str())
103    } else {
104        env!("CARGO_PKG_VERSION")
105    }
106}
107
108mod shared;
109pub mod traits;