luaur_analysis/records/
path.rs1use crate::type_aliases::component::Component;
3use alloc::vec::Vec;
4
5#[derive(Debug, Clone, Default, PartialEq)]
6pub struct Path {
7 pub components: Vec<Component>,
8}
9
10impl Path {
11 pub fn from_component(component: Component) -> Path {
13 Path {
14 components: alloc::vec![component],
15 }
16 }
17
18 pub fn from_components(components: Vec<Component>) -> Path {
20 Path { components }
21 }
22
23 pub fn append(&self, suffix: &Path) -> Path {
24 let mut joined = self.components.clone();
25 joined.reserve(suffix.components.len());
26 joined.extend(suffix.components.iter().cloned());
27 Path { components: joined }
28 }
29
30 pub fn push(&self, component: Component) -> Path {
31 let mut joined = self.components.clone();
32 joined.push(component);
33 Path { components: joined }
34 }
35
36 pub fn push_front(&self, component: Component) -> Path {
37 let mut joined = Vec::with_capacity(self.components.len() + 1);
38 joined.push(component);
39 joined.extend(self.components.iter().cloned());
40 Path { components: joined }
41 }
42
43 pub fn pop(&self) -> Path {
44 if self.path_empty() {
45 return Path::default(); }
47 let mut popped = self.components.clone();
48 popped.pop();
49 Path { components: popped }
50 }
51
52 pub fn last(&self) -> Option<Component> {
53 self.components.last().cloned()
54 }
55
56 pub fn path_empty(&self) -> bool {
58 self.components.is_empty()
59 }
60
61 pub fn operator_eq(&self, other: &Path) -> bool {
62 self.components == other.components
63 }
64}