platform_info/
lib_impl.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// "plumbing" setup and connections for `lib.rs`

#![warn(unused_results)] // enable warnings for unused results

#[cfg(target_os = "windows")]
use std::path::Path;
#[cfg(target_os = "windows")]
use std::path::PathBuf;

//=== types

/// Standard thread-safe error type
pub type ThreadSafeStdError = dyn std::error::Error + Send + Sync;
/// Standard thread-safe error type (boxed to allow translation for any `std::error::Error` type)
pub type BoxedThreadSafeStdError = Box<ThreadSafeStdError>;

/// A slice of a path string
/// (akin to [`str`]; aka/equivalent to [`Path`]).
#[cfg(target_os = "windows")]
type PathStr = Path;
/// An owned, mutable path string
/// (akin to [`String`]; aka/equivalent to [`PathBuf`]).
#[cfg(target_os = "windows")]
type PathString = PathBuf;

//=== platform-specific const

// HOST_OS_NAME * ref: [`uname` info](https://en.wikipedia.org/wiki/Uname)
const HOST_OS_NAME: &str = if cfg!(all(
    target_os = "linux",
    any(target_env = "gnu", target_env = "")
)) {
    "GNU/Linux"
} else if cfg!(all(
    target_os = "linux",
    not(any(target_env = "gnu", target_env = ""))
)) {
    "Linux"
} else if cfg!(target_os = "android") {
    "Android"
} else if cfg!(target_os = "windows") {
    "MS/Windows" // prior art == `busybox`
} else if cfg!(target_os = "freebsd") {
    "FreeBSD"
} else if cfg!(target_os = "netbsd") {
    "NetBSD"
} else if cfg!(target_os = "openbsd") {
    "OpenBSD"
} else if cfg!(target_vendor = "apple") {
    "Darwin"
} else if cfg!(target_os = "fuchsia") {
    "Fuchsia"
} else if cfg!(target_os = "redox") {
    "Redox"
} else if cfg!(target_os = "illumos") {
    "illumos"
} else if cfg!(target_os = "solaris") {
    "solaris"
} else {
    "unknown"
};

//=== platform-specific module code

#[cfg(unix)]
#[path = "platform/unix.rs"]
mod target;
#[cfg(windows)]
#[path = "platform/windows.rs"]
mod target;
#[cfg(not(any(unix, windows)))]
#[path = "platform/unknown.rs"]
mod target;

pub use target::*;