sysprims_core/lib.rs
1//! sysprims-core: Core types, errors, and platform abstractions
2//!
3//! This crate provides the foundational types used across all sysprims modules:
4//! - Error types per ADR-0008
5//! - Schema ID constants for JSON output contracts
6//! - Re-exports from rsfulmen for signal and exit code constants
7//! - Platform detection utilities
8//!
9//! ## Error Handling
10//!
11//! sysprims uses a single canonical error type [`SysprimsError`] that maps
12//! cleanly to FFI error codes. See ADR-0008 for the full strategy.
13//!
14//! ## Schema Integration
15//!
16//! JSON outputs include `schema_id` fields referencing schemas hosted at
17//! `schemas.3leaps.dev/sysprims/`. See the [`schema`] module for constants.
18//!
19//! ## Ecosystem Integration
20//!
21//! Signal and exit code constants are re-exported from rsfulmen for
22//! Fulmen ecosystem alignment. Access via [`signals`] and [`exit_codes`].
23
24use std::env::consts::OS;
25
26pub mod error;
27pub mod guard_signals;
28pub mod schema;
29pub mod time;
30
31// Re-export canonical error type at crate root
32pub use error::{SysprimsError, SysprimsResult};
33
34// Re-export rsfulmen foundry types for ecosystem alignment
35// Using module re-exports (not glob) to keep origin obvious and avoid pollution
36pub use rsfulmen::foundry::exit_codes;
37pub use rsfulmen::foundry::signals;
38
39// ============================================================================
40// Platform Detection
41// ============================================================================
42
43/// Get the current platform identifier.
44///
45/// Returns one of: "linux", "macos", "windows", "freebsd", etc.
46///
47/// This is a pure function with no side effects.
48#[inline]
49pub fn get_platform() -> &'static str {
50 OS
51}
52
53/// Check if running on a Unix-like platform.
54#[inline]
55#[cfg(unix)]
56pub const fn is_unix() -> bool {
57 true
58}
59
60#[inline]
61#[cfg(not(unix))]
62pub const fn is_unix() -> bool {
63 false
64}
65
66/// Check if running on Windows.
67#[inline]
68#[cfg(windows)]
69pub const fn is_windows() -> bool {
70 true
71}
72
73#[inline]
74#[cfg(not(windows))]
75pub const fn is_windows() -> bool {
76 false
77}
78
79#[cfg(test)]
80mod tests {
81 use super::*;
82
83 #[test]
84 fn test_get_platform() {
85 let platform = get_platform();
86 assert!(!platform.is_empty());
87 // Platform should be one of the known values
88 assert!(
89 ["linux", "macos", "windows", "freebsd"].contains(&platform),
90 "Unexpected platform: {}",
91 platform
92 );
93 }
94
95 #[test]
96 fn test_platform_detection_consistency() {
97 // On Unix, is_unix should be true
98 #[cfg(unix)]
99 {
100 assert!(is_unix());
101 assert!(!is_windows());
102 }
103
104 // On Windows, is_windows should be true
105 #[cfg(windows)]
106 {
107 assert!(is_windows());
108 assert!(!is_unix());
109 }
110 }
111
112 #[test]
113 fn test_rsfulmen_reexports() {
114 // Verify rsfulmen constants are accessible through our re-exports
115 assert_eq!(signals::SIGTERM, 15);
116 assert_eq!(signals::SIGKILL, 9);
117 assert_eq!(exit_codes::EXIT_SUCCESS, 0);
118 assert_eq!(exit_codes::EXIT_SIGNAL_TERM, 143);
119 }
120}