1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
mod components;
mod iter;
mod path;
mod pathbuf;

#[macro_use]
pub(crate) mod parser;

use std::hash::Hasher;

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

use crate::private;

/// Interface to provide meaning to a byte slice such that paths can be derived
pub trait Encoding<'a>: private::Sealed {
    /// Represents the type of component that will be derived by this encoding
    type Components: 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: &'a [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]);
}