typed_path/common/non_utf8.rs
1mod components;
2mod iter;
3mod path;
4mod pathbuf;
5
6#[macro_use]
7pub(crate) mod parser;
8
9use core::hash::Hasher;
10
11pub use components::*;
12pub use iter::*;
13pub use parser::ParseError;
14pub use path::*;
15pub use pathbuf::*;
16
17use crate::common::errors::CheckedPathError;
18use crate::no_std_compat::*;
19use crate::private;
20
21/// Interface to provide meaning to a byte slice such that paths can be derived
22pub trait Encoding: private::Sealed {
23 /// Represents the type of component that will be derived by this encoding
24 type Components<'a>: Components<'a>;
25
26 /// Static label representing encoding type
27 fn label() -> &'static str;
28
29 /// Produces an iterator of [`Component`]s over the given the byte slice (`path`)
30 fn components(path: &[u8]) -> Self::Components<'_>;
31
32 /// Hashes a byte slice (`path`)
33 fn hash<H: Hasher>(path: &[u8], h: &mut H);
34
35 /// Pushes a byte slice (`path`) onto the an existing path (`current_path`)
36 fn push(current_path: &mut Vec<u8>, path: &[u8]);
37
38 /// Like [`Encoding::push`], but enforces several new rules:
39 ///
40 /// 1. `path` cannot contain a prefix component.
41 /// 2. `path` cannot contain a root component.
42 /// 3. `path` cannot contain invalid filename bytes.
43 /// 4. `path` cannot contain parent components such that the current path would be escaped.
44 fn push_checked(current_path: &mut Vec<u8>, path: &[u8]) -> Result<(), CheckedPathError>;
45}