paved/
lib.rs

1use std::ffi::OsString;
2
3#[cfg(feature = "serde")]
4use serde::{Deserialize, Serialize};
5use thiserror::Error;
6
7#[cfg(test)]
8mod tests;
9
10mod paved_path;
11
12pub use paved_path::PavedPath;
13
14/// The path separator used on Unix-like systems
15pub const UNIX_PATH_SEPARATOR: char = '/';
16
17/// The path separator used on Windows systems
18pub const WINDOWS_PATH_SEPARATOR: char = '\\';
19
20/// The path separator used on the target platform of the binary, decided at compile-time
21pub const CURRENT_PATH_SEPARATOR: char = if cfg!(windows) {
22    WINDOWS_PATH_SEPARATOR
23} else {
24    UNIX_PATH_SEPARATOR
25};
26
27/// Specifies the type of path this is, either absolute or relative
28#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
29#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Default)]
30pub enum PathType {
31    /// Absolute path
32    #[default]
33    Absolute,
34
35    /// Relative Path
36    Relative,
37}
38
39/// Specification for Windows path prefixes, only useful for Windows paths
40#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
41#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
42pub enum PathPrefix {
43    /// The "drive letter" of a specific device mount point
44    Drive(char),
45
46    /// A UNC path prefix used for network devices in Windows in order of apperance in paths
47    UNC(OsString, OsString),
48}
49
50/// The output style for a path, this is used to choose a representation when building a path, unused internally. [`AsRef<PathBuf>`] on [`PavedPath`] will always return the platform native option depending on the platform the binary was built for.
51#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
52#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default)]
53pub enum PlatformStyle {
54    #[default]
55    Unix,
56    Windows,
57}
58
59#[derive(Error, Debug, Eq, PartialEq, Ord, PartialOrd, Clone, Copy)]
60pub enum PavedAbsolutizeError {
61    #[error("The root path is relative")]
62    RootIsRelative,
63
64    #[error("The path is already absolute")]
65    PathIsAbsolute,
66}