plat/
lib.rs

1pub struct Platform;
2
3impl Platform {
4    pub const MAC: bool = cfg!(target_os = "macos");
5    pub const WIN: bool = cfg!(target_os = "windows");
6    pub const IOS: bool = cfg!(target_os = "ios");
7    pub const ANDROID: bool = cfg!(target_os = "android");
8    pub const MOBILE: bool = Self::IOS || Self::ANDROID;
9    pub const DESKTOP: bool = !Self::MOBILE;
10    pub const WASM: bool = cfg!(target_arch = "wasm32");
11}
12
13impl Platform {
14    pub fn dump() {
15        dbg!(Self::MAC);
16        dbg!(Self::WIN);
17        dbg!(Self::IOS);
18        dbg!(Self::ANDROID);
19        dbg!(Self::MOBILE);
20        dbg!(Self::DESKTOP);
21        dbg!(Self::WASM);
22    }
23}
24
25pub fn platforms() {
26    cfg_aliases::cfg_aliases! {
27        wasm:    { target_arch = "wasm32" },
28
29        android: { target_os = "android" },
30        ios:     { target_os = "ios" },
31
32        macos:   { target_os = "macos" },
33        linux:   { target_os = "linux" },
34
35        mobile:  { any(    target_os = "android", target_os = "ios")  },
36        desktop: { not(any(target_os = "android", target_os = "ios")) },
37
38        not_android: { not(target_os = "android") },
39    }
40}
41
42#[cfg(test)]
43mod test {
44    use crate::Platform;
45
46    #[test]
47    fn test() {
48        Platform::dump();
49    }
50}