paved 0.6.0

A simple platform agnostic path representation
Documentation
use std::ffi::OsString;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use thiserror::Error;

#[cfg(test)]
mod tests;

mod paved_path;

pub use paved_path::PavedPath;

/// The path separator used on Unix-like systems
pub const UNIX_PATH_SEPARATOR: char = '/';

/// The path separator used on Windows systems
pub const WINDOWS_PATH_SEPARATOR: char = '\\';

/// The path separator used on the target platform of the binary, decided at compile-time
pub const CURRENT_PATH_SEPARATOR: char = if cfg!(windows) {
    WINDOWS_PATH_SEPARATOR
} else {
    UNIX_PATH_SEPARATOR
};

/// Specifies the type of path this is, either absolute or relative
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Default)]
pub enum PathType {
    /// Absolute path
    #[default]
    Absolute,

    /// Relative Path
    Relative,
}

/// Specification for Windows path prefixes, only useful for Windows paths
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub enum PathPrefix {
    /// The "drive letter" of a specific device mount point
    Drive(char),

    /// A UNC path prefix used for network devices in Windows in order of apperance in paths
    UNC(OsString, OsString),
}

/// 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.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default)]
pub enum PlatformStyle {
    #[default]
    Unix,
    Windows,
}

#[derive(Error, Debug, Eq, PartialEq, Ord, PartialOrd, Clone, Copy)]
pub enum PavedAbsolutizeError {
    #[error("The root path is relative")]
    RootIsRelative,

    #[error("The path is already absolute")]
    PathIsAbsolute,
}