Skip to main content

use_os/
lib.rs

1#![forbid(unsafe_code)]
2#![doc = include_str!("../README.md")]
3
4pub use use_architecture as architecture;
5pub use use_env_key as env_key;
6pub use use_env_value as env_value;
7pub use use_os_family as os_family;
8pub use use_platform as platform;
9pub use use_process_id as process_id;
10pub use use_process_status as process_status;
11pub use use_thread_id as thread_id;
12pub use use_thread_name as thread_name;
13
14/// Common primitive OS-facing vocabulary reexports.
15pub mod prelude {
16    pub use use_architecture::{Architecture, ArchitectureParseError};
17    pub use use_env_key::{EnvKey, EnvKeyError};
18    pub use use_env_value::{EnvPair, EnvValue};
19    pub use use_os_family::{OsFamily, OsFamilyParseError};
20    pub use use_platform::{Platform, PlatformTriple, PlatformTripleError};
21    pub use use_process_id::{ParentProcessId, ProcessId, ProcessIdError};
22    pub use use_process_status::{
23        ProcessOutcome, ProcessState, ProcessStateParseError, ProcessStatus,
24    };
25    pub use use_thread_id::{ThreadIdLabel, ThreadIdLabelError};
26    pub use use_thread_name::{ThreadCount, ThreadCountError, ThreadName, ThreadNameError};
27}
28
29#[cfg(test)]
30mod tests {
31    use super::prelude::{
32        Architecture, EnvKey, EnvPair, EnvValue, OsFamily, Platform, PlatformTriple, ProcessId,
33        ProcessOutcome, ProcessState, ProcessStatus, ThreadCount, ThreadIdLabel, ThreadName,
34    };
35
36    #[test]
37    fn facade_exposes_os_vocabulary_without_execution() {
38        let family: OsFamily = "linux".parse().unwrap();
39        let architecture: Architecture = "amd64".parse().unwrap();
40        let platform = Platform::new(PlatformTriple::new("x86_64-unknown-linux-gnu").unwrap());
41        let process_id = ProcessId::new(42).unwrap();
42        let status = ProcessStatus::new(ProcessState::Exited).with_status_code(0);
43        let outcome = ProcessOutcome::for_process(process_id, status);
44        let thread_label = ThreadIdLabel::label("worker-1").unwrap();
45        let thread_name = ThreadName::new("worker").unwrap();
46        let thread_count = ThreadCount::new(4).unwrap();
47        let env_pair = EnvPair::new(EnvKey::new("RUST_LOG").unwrap(), EnvValue::new("info"));
48
49        assert_eq!(family, OsFamily::Unix);
50        assert_eq!(architecture, Architecture::X86_64);
51        assert_eq!(platform.to_string(), "x86_64-unknown-linux-gnu");
52        assert_eq!(outcome.process_id(), Some(process_id));
53        assert_eq!(outcome.status_code(), Some(0));
54        assert_eq!(thread_label.to_string(), "worker-1");
55        assert_eq!(thread_name.as_str(), "worker");
56        assert_eq!(thread_count.get(), 4);
57        assert_eq!(env_pair.to_string(), "RUST_LOG=info");
58    }
59}