sys only.Expand description
System information types for building type-safe system-level applications.
This module provides strongly-typed abstractions for common system information concepts, ensuring type safety and preventing common errors in system programming.
§Design Rules
All types in this module follow the core design rules, which adhere to Rust API Guidelines:
§1. Type Safety (C-NEWTYPE, C-CUSTOM-TYPE)
- Strong types prevent mixing incompatible values
- Arguments convey meaning through types, not
boolorOption - All validation performed at construction time
- No runtime errors from invalid states
- Invalid states are unrepresentable
§2. Zero-Cost Abstractions
- No runtime overhead compared to using primitive types
- All validation happens at compile time or construction
- Subsequent operations have zero cost
- Use
#[repr(transparent)]for newtypes over primitive types
§3. Compile-Time Constants
Arch::current()andOsType::current()return compile-time constants- These reflect the target platform, not runtime detection
- Cross-compilation safe
§4. Composability (C-COMMON-TRAITS, C-CONV-TRAITS)
All types implement standard traits:
- Common traits (C-COMMON-TRAITS):
Debugfor debuggingClonefor copyingDisplayfor formattingHashfor use in hash mapsEqandPartialEqfor equalityOrdandPartialOrdfor ordering (where applicable)
- Conversion traits (C-CONV-TRAITS):
FromStrfor parsing from stringsFromfor infallible conversionsTryFromfor fallible conversions
§5. Security (C-SEND-SYNC, C-GOOD-ERR)
- Types are
SendandSyncwhere possible (C-SEND-SYNC) - Error types implement
std::error::Error,Send,Sync(C-GOOD-ERR) - No unsafe code allowed
§6. Explicit Over Implicit (C-DEREF, C-CTOR)
- Only smart pointers implement
DerefandDerefMut(C-DEREF) - Constructors are static, inherent methods (C-CTOR)
- Prefer explicit constructors
- Clear, readable code over clever abstractions
§Types
This module includes types for:
- Architecture: CPU architecture enumeration (
Arch) - Operating System: OS type enumeration (
OsType) - OS Version: Version numbers for OS releases (
OsVersion) - Kernel Version: Linux/Unix kernel versions with release strings (
KernelVersion) - System Hostname: System hostname with RFC 1123 validation (
Hostname) - System Username: POSIX-compliant system username (
Username) - OS Distribution: OS distribution name with family detection (
Distro) - Process ID: Type-safe process identifier (
Pid) - File Descriptor: Type-safe file descriptor (
Fd)
Note: Hostname is re-exported from the net module as it uses the same
RFC 1123 validation rules for both network and system contexts.
§Features
This module requires sys feature to be enabled.
[dependencies]
bare-types = { version = "0.1", features = ["sys"] }§no_std Support
This module is fully no_std compatible. All types are built on core
and do not require the standard library.
To use in a no_std environment:
[dependencies]
bare-types = { version = "0.1", default-features = false, features = ["sys"] }The std feature can be optionally enabled for std::error::Error implementations.
Re-exports§
pub use arch::Arch;pub use arch::ArchError;pub use distro::Distro;pub use distro::DistroError;pub use fd::Fd;pub use fd::FdError;pub use kernel_version::KernelVersion;pub use kernel_version::KernelVersionError;pub use os_type::OsType;pub use os_type::OsTypeError;pub use os_version::OsVersion;pub use os_version::OsVersionError;pub use pid::Pid;pub use pid::PidError;pub use username::Username;pub use username::UsernameError;pub use crate::net::Hostname;pub use crate::net::HostnameError;
Modules§
- arch
- CPU architecture type for system information.
- distro
- OS distribution type for system information.
- fd
- File descriptor type for system information.
- kernel_
version - Kernel version type for system information.
- os_type
- Operating system type for system information.
- os_
version - Operating system version type for system information.
- pid
- Process ID type for system information.
- username
- System username type for system information.