typed_path/common/
utf8.rs

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