typed-path 0.12.3

Provides typed variants of Path and PathBuf for Unix and Windows
Documentation
mod components;
mod iter;
mod path;
mod pathbuf;

#[macro_use]
pub(crate) mod parser;

use core::hash::Hasher;

pub use components::*;
pub use iter::*;
pub use parser::ParseError;
pub use path::*;
pub use pathbuf::*;

use crate::common::errors::CheckedPathError;
use crate::no_std_compat::*;
use crate::private;

/// Interface to provide meaning to a byte slice such that paths can be derived
pub trait Encoding: private::Sealed {
    /// Represents the type of component that will be derived by this encoding
    type Components<'a>: Components<'a>;

    /// Static label representing encoding type
    fn label() -> &'static str;

    /// Produces an iterator of [`Component`]s over the given the byte slice (`path`)
    fn components(path: &[u8]) -> Self::Components<'_>;

    /// Hashes a byte slice (`path`)
    fn hash<H: Hasher>(path: &[u8], h: &mut H);

    /// Pushes a byte slice (`path`) onto the an existing path (`current_path`)
    fn push(current_path: &mut Vec<u8>, path: &[u8]);

    /// Like [`Encoding::push`], but enforces several new rules:
    ///
    /// 1. `path` cannot contain a prefix component.
    /// 2. `path` cannot contain a root component.
    /// 3. `path` cannot contain invalid filename bytes.
    /// 4. `path` cannot contain parent components such that the current path would be escaped.
    fn push_checked(current_path: &mut Vec<u8>, path: &[u8]) -> Result<(), CheckedPathError>;
}