diff options
author | qkzk <qu3nt1n@gmail.com> | 2022-12-20 23:46:13 +0100 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2022-12-20 23:46:13 +0100 |
commit | c10b023eeac815039a4e4e2cbf813b422f20ef6a (patch) | |
tree | b44bcb2c942fac6d96b99445d674f3e8e68ce5d6 /src/visited.rs | |
parent | 9d02d2ea37a75625da64d1e3f16cf6026d30ea8d (diff) |
use macro to impl indexed_vector
Diffstat (limited to 'src/visited.rs')
-rw-r--r-- | src/visited.rs | 43 |
1 files changed, 2 insertions, 41 deletions
diff --git a/src/visited.rs b/src/visited.rs index 7f8ea27..a01c28d 100644 --- a/src/visited.rs +++ b/src/visited.rs @@ -1,6 +1,6 @@ use std::path::PathBuf; -use crate::indexed_vector::IndexedVector; +use crate::impl_indexed_vector; /// A Vec of pathbuf of visited files. /// It's mostly used as a stack but we want to avoid multiple instances of the @@ -41,43 +41,4 @@ impl History { } } -impl IndexedVector<PathBuf> for History { - /// True if nothing was visited. Shouldn't be the case... - fn is_empty(&self) -> bool { - self.content.is_empty() - } - - /// Number of visited paths. - fn len(&self) -> usize { - self.content.len() - } - - /// Select the next visited path. - fn next(&mut self) { - if self.is_empty() { - self.index = 0 - } else if self.index > 0 { - self.index -= 1; - } else { - self.index = self.len() - 1 - } - } - - /// Select the previously visited path. - fn prev(&mut self) { - if self.is_empty() { - self.index = 0; - } else { - self.index = (self.index + 1) % self.len() - } - } - - /// Returns the currently selected visited path. - fn selected(&self) -> Option<&PathBuf> { - if self.index < self.len() { - Some(&self.content[self.index]) - } else { - None - } - } -} +impl_indexed_vector!(PathBuf, History); |