cross_path/platform/
mod.rs

1//! Platform-specific path handling operations
2//!
3//! This module provides traits and structures for handling platform-specific
4//! path operations, file attributes, and disk information.
5//!
6//! It abstracts away the differences between Windows and Unix-like systems,
7//! allowing for uniform access to filesystem metadata.
8
9#[cfg(not(target_os = "windows"))]
10pub mod unix;
11#[cfg(target_os = "windows")]
12pub mod windows;
13
14use alloc::string::String;
15use core::option::Option;
16#[cfg(not(target_os = "windows"))]
17pub use unix::UnixPathExt;
18#[cfg(target_os = "windows")]
19pub use windows::WindowsPathExt;
20
21use super::PathStyle;
22
23/// Get current platform path style
24#[must_use]
25pub fn current_style() -> PathStyle {
26    #[cfg(target_os = "windows")]
27    {
28        PathStyle::Windows
29    }
30
31    #[cfg(not(target_os = "windows"))]
32    {
33        PathStyle::Unix
34    }
35}
36
37/// Platform-specific path operations
38pub trait PlatformPath {
39    /// Get platform-specific path separator
40    fn separator(&self) -> char;
41
42    /// Check if path is absolute
43    fn is_absolute(&self) -> bool;
44
45    /// Convert to platform-specific canonical path
46    fn to_platform_specific(&self) -> String;
47}
48
49/// Platform extension trait
50pub trait PathExt: PlatformPath {
51    /// Get file attributes (platform-specific)
52    fn get_attributes(&self) -> Option<FileAttributes>;
53
54    /// Check if path exists and is accessible
55    fn is_accessible(&self) -> bool;
56
57    /// Get disk information for path
58    fn get_disk_info(&self) -> Option<DiskInfo>;
59}
60
61/// File attributes structure
62#[derive(Debug, Clone)]
63pub struct FileAttributes {
64    /// File size in bytes
65    pub size: u64,
66    /// Whether the file is a directory
67    pub is_directory: bool,
68    /// Whether the file is hidden
69    pub is_hidden: bool,
70    /// Whether the file is read-only
71    pub is_readonly: bool,
72    /// Creation timestamp (if available)
73    pub creation_time: Option<u64>,
74    /// Last modification timestamp (if available)
75    pub modification_time: Option<u64>,
76}
77
78/// Disk information structure
79#[derive(Debug, Clone)]
80pub struct DiskInfo {
81    /// Total disk space in bytes
82    pub total_space: u64,
83    /// Free disk space in bytes
84    pub free_space: u64,
85    /// Filesystem type name (e.g., "NTFS", "ext4")
86    pub filesystem_type: String,
87}