Skip to main content

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//! - **Process ID**: Type-safe process identifier (`Pid`)
72//! - **File Descriptor**: Type-safe file descriptor (`Fd`)
73//!
74//! Note: `Hostname` is re-exported from the `net` module as it uses the same
75//! RFC 1123 validation rules for both network and system contexts.
76//!
77//! ## Features
78//!
79//! This module requires `sys` feature to be enabled.
80//!
81//! ```toml
82//! [dependencies]
83//! bare-types = { version = "0.1", features = ["sys"] }
84//! ```
85//!
86//! ## `no_std` Support
87//!
88//! This module is fully `no_std` compatible. All types are built on `core`
89//! and do not require the standard library.
90//!
91//! To use in a `no_std` environment:
92//!
93//! ```toml
94//! [dependencies]
95//! bare-types = { version = "0.1", default-features = false, features = ["sys"] }
96//! ```
97//!
98//! The `std` feature can be optionally enabled for `std::error::Error` implementations.
99
100pub mod arch;
101pub mod distro;
102pub mod fd;
103pub mod kernel_version;
104pub mod os_type;
105pub mod os_version;
106pub mod pid;
107pub mod username;
108
109pub use arch::{Arch, ArchError};
110pub use distro::{Distro, DistroError};
111pub use fd::{Fd, FdError};
112pub use kernel_version::{KernelVersion, KernelVersionError};
113pub use os_type::{OsType, OsTypeError};
114pub use os_version::{OsVersion, OsVersionError};
115pub use pid::{Pid, PidError};
116pub use username::{Username, UsernameError};
117
118// Re-export Hostname from net module for sys context
119pub use crate::net::{Hostname, HostnameError};