is_tree/traits/
is_path_segment.rs

1//! Traits for types that can be used as path segments.
2
3use std::hash::Hash;
4
5use crate::PathSegment;
6
7/// A trait for types that can be used as path segments.
8pub trait IsPathSegment: PartialEq + Eq + Hash + Clone {
9    /// Gets the root path segment.
10    fn root() -> Self;
11    /// Gets the self path segment.
12    fn self_() -> Self;
13    /// Gets the super path segment.
14    fn super_() -> Self;
15    /// Gets the kind of path segment.
16    fn kind(&self) -> PathSegment<&Self> {
17        if Self::root().eq(self) {
18            PathSegment::Root
19        } else if Self::self_().eq(self) {
20            PathSegment::Self_
21        } else if Self::super_().eq(self) {
22            PathSegment::Super
23        } else {
24            PathSegment::Other(self)
25        }
26    }
27}
28
29impl IsPathSegment for String {
30    fn root() -> Self {
31        "root".to_string()
32    }
33    fn self_() -> Self {
34        "self".to_string()
35    }
36    fn super_() -> Self {
37        "super".to_string()
38    }
39}