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
36
37
38
39
//! Traits for types that can be used as path segments.

use std::hash::Hash;

use crate::PathSegment;

/// A trait for types that can be used as path segments.
pub trait IsPathSegment: PartialEq + Eq + Hash + Clone {
    /// Gets the root path segment.
    fn root() -> Self;
    /// Gets the self path segment.
    fn self_() -> Self;
    /// Gets the super path segment.
    fn super_() -> Self;
    /// Gets the kind of path segment.
    fn kind(&self) -> PathSegment<&Self> {
        if Self::root().eq(self) {
            PathSegment::Root
        } else if Self::self_().eq(self) {
            PathSegment::Self_
        } else if Self::super_().eq(self) {
            PathSegment::Super
        } else {
            PathSegment::Other(self)
        }
    }
}

impl IsPathSegment for String {
    fn root() -> Self {
        "root".to_string()
    }
    fn self_() -> Self {
        "self".to_string()
    }
    fn super_() -> Self {
        "super".to_string()
    }
}