pub trait Platform: Send + Sync {
// Required methods
fn page_size(&self) -> usize;
fn cpu_count(&self) -> usize;
fn total_memory(&self) -> Result<u64, PlatformError>;
fn available_memory(&self) -> Result<u64, PlatformError>;
fn line_separator(&self) -> &'static str;
fn path_separator(&self) -> char;
fn platform_name(&self) -> &'static str;
fn temp_dir(&self) -> PathBuf;
fn is_elevated(&self) -> bool;
fn set_permissions(
&self,
path: &Path,
mode: u32,
) -> Result<(), PlatformError>;
fn is_executable(&self, path: &Path) -> bool;
fn sync_file<'life0, 'life1, 'async_trait>(
&'life0 self,
file: &'life1 File,
) -> Pin<Box<dyn Future<Output = Result<(), PlatformError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}Expand description
Platform abstraction trait for OS-specific operations
This trait provides a clean interface for platform-specific functionality, allowing the bootstrap layer to work with different operating systems without conditional compilation throughout the codebase.
§Design Principles
- Stateless: All methods are stateless and thread-safe
- Async-aware: File operations are async-compatible
- Error-handling: All fallible operations return
Result - Cross-platform: Same interface works on Unix and Windows
§Implementation Notes
Implementations should use native platform APIs:
- Unix: POSIX APIs via
libc,/proc,/sys - Windows: Windows API via
winapi - Fallbacks: Standard Rust APIs when platform APIs unavailable
Required Methods§
Sourcefn page_size(&self) -> usize
fn page_size(&self) -> usize
Get the system page size for memory alignment
Used for:
- Memory-mapped I/O alignment
- Buffer sizing optimizations
- Cache-friendly allocations
§Returns
Page size in bytes (typically 4096 on most systems)
Sourcefn cpu_count(&self) -> usize
fn cpu_count(&self) -> usize
Get the number of available CPU cores
Returns the number of logical processors available to the process. Used for determining optimal parallelism levels.
§Returns
Number of CPU cores (at least 1)
Sourcefn total_memory(&self) -> Result<u64, PlatformError>
fn total_memory(&self) -> Result<u64, PlatformError>
Sourcefn available_memory(&self) -> Result<u64, PlatformError>
fn available_memory(&self) -> Result<u64, PlatformError>
Sourcefn line_separator(&self) -> &'static str
fn line_separator(&self) -> &'static str
Sourcefn path_separator(&self) -> char
fn path_separator(&self) -> char
Get the platform-specific path separator for PATH environment variable
§Returns
- Unix:
':' - Windows:
';'
Sourcefn platform_name(&self) -> &'static str
fn platform_name(&self) -> &'static str
Sourcefn is_elevated(&self) -> bool
fn is_elevated(&self) -> bool
Check if running with elevated privileges
§Returns
- Unix:
trueif effective UID is 0 (root) - Windows:
trueif running as Administrator