Skip to main content

Module sys

Module sys 

Source
Available on crate feature 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 bool or Option
  • 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() and OsType::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):
    • Debug for debugging
    • Clone for copying
    • Display for formatting
    • Hash for use in hash maps
    • Eq and PartialEq for equality
    • Ord and PartialOrd for ordering (where applicable)
  • Conversion traits (C-CONV-TRAITS):
    • FromStr for parsing from strings
    • From for infallible conversions
    • TryFrom for fallible conversions

§5. Security (C-SEND-SYNC, C-GOOD-ERR)

  • Types are Send and Sync where 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 Deref and DerefMut (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)

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 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 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.
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.
username
System username type for system information.