is_tree/traits/
is_path_segment.rs1use std::hash::Hash;
4
5use crate::PathSegment;
6
7pub trait IsPathSegment: PartialEq + Eq + Hash + Clone {
9 fn root() -> Self;
11 fn self_() -> Self;
13 fn super_() -> Self;
15 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}