| 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")] // ToDO: [2023-05-28; rivy] DRY by instead including README.md as crate documentation |
| 22 | /*! |
| 23 | [](https://crates.io/crates/platform-info) |
| 24 | [](https://github.com/uutils/platform-info/tree/main/LICENSE) |
| 25 | [](https://codecov.io/gh/uutils/platform-info/tree/main) |
| 26 | |
| 27 | This crate provides the ability to retrieve information specific to your current platform via a cross-platform |
| 28 | uname-type API ([`UNameAPI`]). Additional platform-specific information may be supplied within [`PlatformInfo`]. |
| 29 | |
| 30 | # Usage |
| 31 | |
| 32 | This crate is available on [crate.io](https://crates.io/crates/platform-info). So, to use it in your project, just add |
| 33 | the following to your project's `Cargo.toml` [dependencies](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html): |
| 34 | |
| 35 | ```toml |
| 36 | [dependencies] |
| 37 | platform-info = "2" |
| 38 | ``` |
| 39 | |
| 40 | # Examples |
| 41 | |
| 42 | ```rust |
| 43 | */ |
| 44 | #![doc = include_str!("../examples/ex.rs")] |
| 45 | /*! |
| 46 | ``` |
| 47 | |
| 48 | Other examples can be found in the [`examples` directory](https://github.com/uutils/platform-info/tree/main/examples) |
| 49 | of this crate and in the [uutils/coreutils](https://github.com/uutils/coreutils) implementation of |
| 50 | [`uname`](https://github.com/uutils/coreutils/blob/main/src/uu/uname/src/uname.rs). |
| 51 | */ |
| 52 | |
| 53 | // spell-checker:ignore (API) nodename osname sysname |
| 54 | // spell-checker:ignore (uutils) coreutils uutils |
| 55 | |
| 56 | #![warn(unused_results)] // enable warnings for unused results |
| 57 | |
| 58 | use std::ffi::OsStr; |
| 59 | |
| 60 | mod lib_impl; |
| 61 | |
| 62 | //=== |
| 63 | |
| 64 | // PlatformInfo |
| 65 | // Handles initial retrieval and holds cached information for the current platform. |
| 66 | pub use lib_impl::PlatformInfo; |
| 67 | #[cfg(unix)] |
| 68 | pub use lib_impl::UTSName; |
| 69 | #[cfg(windows)] |
| 70 | pub use lib_impl::{WinApiSystemInfo, WinOsVersionInfo}; |
| 71 | |
| 72 | // PlatformInfoError |
| 73 | /// The common error type for [`PlatformInfoAPI`]. |
| 74 | pub use lib_impl::BoxedThreadSafeStdError as PlatformInfoError; |
| 75 | |
| 76 | // PlatformInfoAPI |
| 77 | /// Defines the full API for [`PlatformInfo`]. |
| 78 | // * includes `UNameAPI` |
| 79 | pub trait PlatformInfoAPI: UNameAPI { |
| 80 | /// Creates a new instance of [`PlatformInfo`]. |
| 81 | /// <br> On some platforms, it is possible for this function to fail. |
| 82 | fn new() -> Result<Self, PlatformInfoError> |
| 83 | where |
| 84 | Self: Sized; |
| 85 | } |
| 86 | |
| 87 | // UNameAPI |
| 88 | /// Defines a trait API providing `uname` (aka "Unix name") style platform information. |
| 89 | // ref: <https://www.gnu.org/software/libc/manual/html_node/Platform-Type.html> @@ <https://archive.is/YjjWJ> |
| 90 | pub trait UNameAPI { |
| 91 | /// The name of this implementation of the operating system. |
| 92 | fn sysname(&self) -> &OsStr; |
| 93 | |
| 94 | /// The node name (network node hostname) of this machine. |
| 95 | fn nodename(&self) -> &OsStr; |
| 96 | |
| 97 | /// The current release level of the operating system. |
| 98 | fn release(&self) -> &OsStr; |
| 99 | |
| 100 | /// The current version level of the current release. |
| 101 | fn version(&self) -> &OsStr; |
| 102 | |
| 103 | /// The name of the current system's hardware. |
| 104 | fn machine(&self) -> &OsStr; |
| 105 | |
| 106 | /// The name of the current OS. |
| 107 | fn osname(&self) -> &OsStr; |
| 108 | } |