jwalk/core/
index_path.rs
1use std::cmp::Ordering;
2
3#[derive(Clone, Debug)]
4pub struct IndexPath {
5 pub indices: Vec<usize>,
6}
7
8impl IndexPath {
9 pub fn new(indices: Vec<usize>) -> IndexPath {
10 IndexPath { indices }
11 }
12
13 pub fn adding(&self, index: usize) -> IndexPath {
14 let mut indices = self.indices.clone();
15 indices.push(index);
16 IndexPath::new(indices)
17 }
18
19 pub fn push(&mut self, index: usize) {
20 self.indices.push(index);
21 }
22
23 pub fn increment_last(&mut self) {
24 *self.indices.last_mut().unwrap() += 1;
25 }
26
27 pub fn pop(&mut self) -> Option<usize> {
28 self.indices.pop()
29 }
30
31 pub fn is_empty(&self) -> bool {
32 self.indices.is_empty()
33 }
34}
35
36impl PartialEq for IndexPath {
37 fn eq(&self, o: &Self) -> bool {
38 self.indices.eq(&o.indices)
39 }
40}
41
42impl Eq for IndexPath {}
43
44impl PartialOrd for IndexPath {
45 fn partial_cmp(&self, o: &Self) -> Option<Ordering> {
46 o.indices.partial_cmp(&self.indices)
47 }
48}
49
50impl Ord for IndexPath {
51 fn cmp(&self, o: &Self) -> Ordering {
52 o.indices.cmp(&self.indices)
53 }
54}