1use crate::{PathPart, Sym, ast::Path};
3
4impl Path {
5 pub fn push(&mut self, part: PathPart) {
7 self.parts.push(part);
8 }
9 pub fn pop(&mut self) -> Option<PathPart> {
11 self.parts.pop()
12 }
13 pub fn concat(mut self, other: &Self) -> Self {
16 if other.absolute {
17 other.clone()
18 } else {
19 self.parts.extend(other.parts.iter().cloned());
20 self
21 }
22 }
23
24 pub fn as_sym(&self) -> Option<Sym> {
26 match self.parts.as_slice() {
27 [.., PathPart::Ident(name)] => Some(*name),
28 _ => None,
29 }
30 }
31
32 pub fn ends_with(&self, name: &str) -> bool {
34 match self.parts.as_slice() {
35 [.., PathPart::Ident(last)] => name == &**last,
36 _ => false,
37 }
38 }
39
40 pub fn is_sinkhole(&self) -> bool {
42 if let [PathPart::Ident(id)] = self.parts.as_slice() {
43 if let "_" = id.to_ref() {
44 return true;
45 }
46 }
47 false
48 }
49}
50impl PathPart {
51 pub fn from_sym(ident: Sym) -> Self {
52 Self::Ident(ident)
53 }
54}
55
56impl From<Sym> for Path {
57 fn from(value: Sym) -> Self {
58 Self { parts: vec![PathPart::Ident(value)], absolute: false }
59 }
60}