diff options
Diffstat (limited to 'src/visited.rs')
-rw-r--r-- | src/visited.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/visited.rs b/src/visited.rs index b488f0e..1dbd251 100644 --- a/src/visited.rs +++ b/src/visited.rs @@ -1,12 +1,21 @@ use std::path::PathBuf; +/// A Vec of pathbuf of visited files. +/// It's mostly used as a stack but we want to avoid multiple instances of the +/// same path and visit in a certain order. +/// A `BTreeSet` may be used instead. +/// We also need to drop the queue, which isn't easy with a BTreeSet... #[derive(Default, Clone)] pub struct History { + /// The visited paths pub visited: Vec<PathBuf>, + /// The currently selected index. By default it's the last one. pub index: usize, } impl History { + /// Add a new path in the stack, without duplicates, and select the last + /// one. pub fn push(&mut self, path: &PathBuf) { if !self.visited.contains(path) { self.visited.push(path.to_owned()); @@ -14,14 +23,17 @@ impl History { } } + /// True if nothing was visited. Shouldn't be the case... pub fn is_empty(&self) -> bool { self.visited.is_empty() } + /// Number of visited paths. pub fn len(&self) -> usize { self.visited.len() } + /// Select the next visited path. pub fn next(&mut self) { if self.is_empty() { self.index = 0 @@ -32,6 +44,7 @@ impl History { } } + /// Select the previously visited path. pub fn prev(&mut self) { if self.is_empty() { self.index = 0; @@ -40,6 +53,7 @@ impl History { } } + /// Returns the currently selected visited path. pub fn selected(&self) -> Option<PathBuf> { if self.index < self.len() { Some(self.visited[self.index].clone()) @@ -48,6 +62,8 @@ impl History { } } + /// Drop the last visited paths from the stack, after the selected one. + /// Used to go back a few steps in time. pub fn drop_queue(&mut self) { if self.is_empty() { return; |