Skip to main content

file_storage/path/system/
is_windows.rs

1use crate::{FilePath, FolderPath, StoragePath};
2
3impl StoragePath {
4    //! Is System
5
6    /// Checks if the path is a Windows path.
7    pub fn is_windows_path(&self) -> bool {
8        Self::is_windows_path_str(self.path())
9    }
10
11    /// Checks if the `path` is a Windows path.
12    pub fn is_windows_path_str<S>(path: S) -> bool
13    where
14        S: AsRef<str>,
15    {
16        let path: &str = path.as_ref();
17        if path.len() < 3 {
18            false
19        } else {
20            path.as_bytes()[0].is_ascii_alphabetic()
21                && path.as_bytes()[1] == b':'
22                && (path.as_bytes()[2] == b'\\' || path.as_bytes()[2] == b'/')
23        }
24    }
25}
26
27impl FilePath {
28    //! Is System
29
30    /// Checks if the path is a Windows path.
31    pub fn is_windows_path(&self) -> bool {
32        StoragePath::is_windows_path_str(self.as_str())
33    }
34}
35
36impl FolderPath {
37    //! Is System
38
39    /// Checks if the path is a Windows path.
40    pub fn is_windows_path(&self) -> bool {
41        StoragePath::is_windows_path_str(self.as_str())
42    }
43}