Debian Codegraph @

debian/rust-vendor/platform-info/src/lib.rs

raw
1 // This file is part of the uutils coreutils package.
2 //
3 // (c) Alex Lyon <[email protected]>
4 //
5 // For the full copyright and license information, please view the LICENSE file
6 // that was distributed with this source code.
7
8 // spell-checker:ignore (abbrev/names) MSVC POSIX (names) rivy (rust) rustdoc RUSTDOCFLAGS
9
10 // Documentation
11 // See <https://docs.rs/platform-info> or <https://docs.rs/crate/platform-info>.
12 // Use `cargo doc --no-deps --open --target=i686-pc-windows-msvc` to view WinOS documentation for this crate.
13 // Use `cargo doc --no-deps --open --target=i686-unknown-linux-gnu` to view POSIX documentation for this crate.
14 // * note: `cargo rustdoc` is equivalent to `cargo doc --no-deps` and is what `docs.rs` uses to generate documentation.
15 // * ref: <https://users.rust-lang.org/t/docs-rs-does-not-show-my-documentation/70414/4> @@ <https://archive.is/W0N8W>
16
17 // Enable documentation warnings for missing documentation (for public items) and broken intra-doc links.
18 // * note: CI documentation linting has all warnings escalated to errors (using `RUSTDOCFLAGS="--deny warnings" cargo doc`)
19 #![warn(missing_docs)]
20 #![warn(rustdoc::broken_intra_doc_links)]
21 #![doc = include_str!("../README.md")]
22 // spell-checker:ignore (API) nodename osname sysname
23 // spell-checker:ignore (uutils) coreutils uutils
24 #![warn(unsafe_op_in_unsafe_fn)] // require explicit unsafe blocks inside unsafe fns
25 #![warn(unused_results)] // enable warnings for unused results
26
27 use std::ffi::OsStr;
28
29 mod lib_impl;
30
31 //===
32
33 // PlatformInfo
34 // Handles initial retrieval and holds cached information for the current platform.
35 pub use lib_impl::PlatformInfo;
36 #[cfg(unix)]
37 pub use lib_impl::UTSName;
38 #[cfg(windows)]
39 pub use lib_impl::{WinApiSystemInfo, WinOsVersionInfo};
40
41 // PlatformInfoError
42 /// The common error type for [`PlatformInfoAPI`].
43 pub use lib_impl::BoxedThreadSafeStdError as PlatformInfoError;
44
45 // PlatformInfoAPI
46 /// Defines the full API for [`PlatformInfo`].
47 // * includes `UNameAPI`
48 pub trait PlatformInfoAPI: UNameAPI {
49 /// Creates a new instance of [`PlatformInfo`].
50 /// <br> On some platforms, it is possible for this function to fail.
51 ///
52 /// # Errors
53 ///
54 /// Returns a [`PlatformInfoError`] if the underlying OS query fails — for
55 /// example, when `uname()` returns an error on Unix or the Windows API
56 /// calls used to gather system information cannot be completed.
57 fn new() -> Result<Self, PlatformInfoError>
58 where
59 Self: Sized;
60 }
61
62 // UNameAPI
63 /// Defines a trait API providing `uname` (aka "Unix name") style platform information.
64 // ref: <https://www.gnu.org/software/libc/manual/html_node/Platform-Type.html> @@ <https://archive.is/YjjWJ>
65 pub trait UNameAPI {
66 /// The name of this implementation of the operating system.
67 fn sysname(&self) -> &OsStr;
68
69 /// The node name (network node hostname) of this machine.
70 fn nodename(&self) -> &OsStr;
71
72 /// The current release level of the operating system.
73 fn release(&self) -> &OsStr;
74
75 /// The current version level of the current release.
76 fn version(&self) -> &OsStr;
77
78 /// The name of the current system's hardware.
79 fn machine(&self) -> &OsStr;
80
81 /// The processor type (architecture) of the current system.
82 ///
83 /// Maps machine architecture strings to GNU coreutils-compatible processor types.
84 /// For example, "arm64" may map to "arm", `x86_64` to `x86_64`, etc.
85 /// This provides more semantically meaningful processor information than the
86 /// raw machine string in some contexts.
87 fn processor(&self) -> &OsStr;
88
89 /// The name of the current OS.
90 fn osname(&self) -> &OsStr;
91 }