typed_path/common/utf8/
components.rs

1mod component;
2
3use core::{cmp, fmt, iter};
4
5pub use component::*;
6
7use crate::private;
8
9/// Interface of an iterator over a collection of [`Utf8Component`]s
10pub trait Utf8Components<'a>:
11    AsRef<str>
12    + Clone
13    + fmt::Debug
14    + cmp::PartialEq
15    + cmp::Eq
16    + cmp::PartialOrd
17    + cmp::Ord
18    + iter::Iterator<Item = Self::Component>
19    + iter::DoubleEndedIterator<Item = Self::Component>
20    + iter::FusedIterator
21    + Sized
22    + private::Sealed
23{
24    /// Type of [`Utf8Component`] iterated over
25    type Component: Utf8Component<'a>;
26
27    /// Extracts a slice corresponding to the portion of the path remaining for iteration
28    fn as_str(&self) -> &'a str;
29
30    /// Reports back whether the iterator represents an absolute path
31    ///
32    /// The definition of an absolute path can vary:
33    ///
34    /// * On Unix, a path is absolute if it starts with the root, so `is_absolute` and [`has_root`]
35    ///   are equivalent.
36    ///
37    /// * On Windows, a path is absolute if it has a prefix and starts with the root: `c:\windows`
38    ///   is absolute, while `c:temp` and `\temp` are not.
39    ///
40    /// [`has_root`]: Utf8Components::has_root
41    fn is_absolute(&self) -> bool;
42
43    /// Returns `true` if the iterator represents a path that has a root.
44    ///
45    /// The definition of what it means for a path to have a root can vary:
46    ///
47    /// * On Unix, a path has a root if it begins with `/`.
48    ///
49    /// * On Windows, a path has a root if it:
50    ///     * has no prefix and begins with a separator, e.g., `\windows`
51    ///     * has a prefix followed by a separator, e.g., `c:\windows` but not `c:windows`
52    ///     * has any non-disk prefix, e.g., `\\server\share`
53    fn has_root(&self) -> bool;
54}