platform_info/
lib_impl.rs

1// "plumbing" setup and connections for `lib.rs`
2
3#![warn(unused_results)] // enable warnings for unused results
4
5#[cfg(target_os = "windows")]
6use std::path::Path;
7#[cfg(target_os = "windows")]
8use std::path::PathBuf;
9
10//=== types
11
12/// Standard thread-safe error type
13pub type ThreadSafeStdError = dyn std::error::Error + Send + Sync;
14/// Standard thread-safe error type (boxed to allow translation for any `std::error::Error` type)
15pub type BoxedThreadSafeStdError = Box<ThreadSafeStdError>;
16
17/// A slice of a path string
18/// (akin to [`str`]; aka/equivalent to [`Path`]).
19#[cfg(target_os = "windows")]
20type PathStr = Path;
21/// An owned, mutable path string
22/// (akin to [`String`]; aka/equivalent to [`PathBuf`]).
23#[cfg(target_os = "windows")]
24type PathString = PathBuf;
25
26//=== platform-specific const
27
28// HOST_OS_NAME * ref: [`uname` info](https://en.wikipedia.org/wiki/Uname)
29const HOST_OS_NAME: &str = if cfg!(all(
30    target_os = "linux",
31    any(target_env = "gnu", target_env = "")
32)) {
33    "GNU/Linux"
34} else if cfg!(all(
35    target_os = "linux",
36    not(any(target_env = "gnu", target_env = ""))
37)) {
38    "Linux"
39} else if cfg!(target_os = "android") {
40    "Android"
41} else if cfg!(target_os = "windows") {
42    "MS/Windows" // prior art == `busybox`
43} else if cfg!(target_os = "freebsd") {
44    "FreeBSD"
45} else if cfg!(target_os = "netbsd") {
46    "NetBSD"
47} else if cfg!(target_os = "openbsd") {
48    "OpenBSD"
49} else if cfg!(target_vendor = "apple") {
50    "Darwin"
51} else if cfg!(target_os = "fuchsia") {
52    "Fuchsia"
53} else if cfg!(target_os = "redox") {
54    "Redox"
55} else if cfg!(target_os = "illumos") {
56    "illumos"
57} else if cfg!(target_os = "solaris") {
58    "solaris"
59} else {
60    "unknown"
61};
62
63//=== platform-specific module code
64
65#[cfg(unix)]
66#[path = "platform/unix.rs"]
67mod target;
68#[cfg(windows)]
69#[path = "platform/windows.rs"]
70mod target;
71#[cfg(not(any(unix, windows)))]
72#[path = "platform/unknown.rs"]
73mod target;
74
75pub use target::*;