bare_types/sys/mod.rs
1//! System information types for building type-safe system-level applications.
2//!
3//! This module provides strongly-typed abstractions for common system information concepts,
4//! ensuring type safety and preventing common errors in system programming.
5//!
6//! ## Design Rules
7//!
8//! All types in this module follow the core design rules, which adhere to
9//! [Rust API Guidelines](https://rust-lang.github.io/api-guidelines/):
10//!
11//! ### 1. Type Safety (C-NEWTYPE, C-CUSTOM-TYPE)
12//!
13//! - Strong types prevent mixing incompatible values
14//! - Arguments convey meaning through types, not `bool` or `Option`
15//! - All validation performed at construction time
16//! - No runtime errors from invalid states
17//! - Invalid states are unrepresentable
18//!
19//! ### 2. Zero-Cost Abstractions
20//!
21//! - No runtime overhead compared to using primitive types
22//! - All validation happens at compile time or construction
23//! - Subsequent operations have zero cost
24//! - Use `#[repr(transparent)]` for newtypes over primitive types
25//!
26//! ### 3. Compile-Time Constants
27//!
28//! - `Arch::current()` and `OsType::current()` return compile-time constants
29//! - These reflect the target platform, not runtime detection
30//! - Cross-compilation safe
31//!
32//! ### 4. Composability (C-COMMON-TRAITS, C-CONV-TRAITS)
33//!
34//! All types implement standard traits:
35//! - **Common traits** (C-COMMON-TRAITS):
36//! - `Debug` for debugging
37//! - `Clone` for copying
38//! - `Display` for formatting
39//! - `Hash` for use in hash maps
40//! - `Eq` and `PartialEq` for equality
41//! - `Ord` and `PartialOrd` for ordering (where applicable)
42//! - **Conversion traits** (C-CONV-TRAITS):
43//! - `FromStr` for parsing from strings
44//! - `From` for infallible conversions
45//! - `TryFrom` for fallible conversions
46//!
47//! ### 5. Security (C-SEND-SYNC, C-GOOD-ERR)
48//!
49//! - Types are `Send` and `Sync` where possible (C-SEND-SYNC)
50//! - Error types implement `std::error::Error`, `Send`, `Sync` (C-GOOD-ERR)
51//! - No unsafe code allowed
52//!
53//! ### 6. Explicit Over Implicit (C-DEREF, C-CTOR)
54//!
55//! - Only smart pointers implement `Deref` and `DerefMut` (C-DEREF)
56//! - Constructors are static, inherent methods (C-CTOR)
57//! - Prefer explicit constructors
58//! - Clear, readable code over clever abstractions
59//!
60//! ## Types
61//!
62//! This module includes types for:
63//!
64//! - **Architecture**: CPU architecture enumeration (`Arch`)
65//! - **Operating System**: OS type enumeration (`OsType`)
66//! - **OS Version**: Version numbers for OS releases (`OsVersion`)
67//! - **Kernel Version**: Linux/Unix kernel versions with release strings (`KernelVersion`)
68//! - **System Hostname**: System hostname with RFC 1123 validation (`Hostname`)
69//! - **System Username**: POSIX-compliant system username (`Username`)
70//! - **OS Distribution**: OS distribution name with family detection (`Distro`)
71//!
72//! Note: `Hostname` is re-exported from the `net` module as it uses the same
73//! RFC 1123 validation rules for both network and system contexts.
74//!
75//! ## Features
76//!
77//! This module requires `sys` feature to be enabled.
78//!
79//! ```toml
80//! [dependencies]
81//! bare-types = { version = "0.1", features = ["sys"] }
82//! ```
83//!
84//! ## `no_std` Support
85//!
86//! This module is fully `no_std` compatible. All types are built on `core`
87//! and do not require the standard library.
88//!
89//! To use in a `no_std` environment:
90//!
91//! ```toml
92//! [dependencies]
93//! bare-types = { version = "0.1", default-features = false, features = ["sys"] }
94//! ```
95//!
96//! The `std` feature can be optionally enabled for `std::error::Error` implementations.
97
98pub mod arch;
99pub mod distro;
100pub mod kernel_version;
101pub mod os_type;
102pub mod os_version;
103pub mod username;
104
105pub use arch::{Arch, ArchError};
106pub use distro::{Distro, DistroError};
107pub use kernel_version::{KernelVersion, KernelVersionError};
108pub use os_type::{OsType, OsTypeError};
109pub use os_version::{OsVersion, OsVersionError};
110pub use username::{Username, UsernameError};
111
112// Re-export Hostname from net module for sys context
113pub use crate::net::{Hostname, HostnameError};