diff --git a/src/matched_path.rs b/src/matched_path.rs index 5a6b32a5..411e3637 100644 --- a/src/matched_path.rs +++ b/src/matched_path.rs @@ -6,7 +6,7 @@ use std::fmt::{self, Display, Formatter}; pub(crate) struct MatchedPath { absolute: String, relative: String, - positions: Vec, + positions: VecDeque, depth: usize, } @@ -29,11 +29,6 @@ impl MatchedPath { &self.relative } - #[allow(dead_code)] // TODO: Use it later - pub(crate) fn positions(&self) -> &[usize] { - self.positions.as_slice() - } - /// Calculate the total distance between each position. /// For example, if the `positions` is `vec![1, 2, 3]`, then the distance will be `2`. /// If the `positions` is `vec![1, 4, 5]`, then the distance will be `4`. @@ -106,7 +101,7 @@ fn depth_from<'a>(relative: impl Iterator) -> usize { /// Calculates matched positions of `relative` with `query`. /// This searches for characters of `query` in `relative` from the right one by one. -fn positions_from(query: &str, relative: &[char]) -> Option> { +fn positions_from(query: &str, relative: &[char]) -> Option> { let mut positions: VecDeque = VecDeque::with_capacity(query.len()); for char in normalize_query(query).chars().rev() { let end = if let Some(pos) = positions.front() { @@ -118,7 +113,7 @@ fn positions_from(query: &str, relative: &[char]) -> Option> { let pos = target.iter().rposition(|t| char.eq_ignore_ascii_case(t))?; positions.push_front(pos); } - Some(Vec::from(positions)) + Some(positions) } #[cfg(target_os = "windows")] @@ -148,7 +143,7 @@ mod tests { MatchedPath { absolute: String::from("/abc/abc/abc.txt"), relative: String::from("abc/abc/abc.txt"), - positions: vec![8, 9, 10, 11, 12, 13, 14], + positions: VecDeque::from(vec![8, 9, 10, 11, 12, 13, 14]), depth: 2, }, ); @@ -157,7 +152,7 @@ mod tests { MatchedPath { absolute: String::from("/abc/abc/abc.txt"), relative: String::from("abc/abc/abc.txt"), - positions: vec![8, 9, 10], + positions: VecDeque::from(vec![8, 9, 10]), depth: 2, }, ); @@ -170,7 +165,7 @@ mod tests { MatchedPath { absolute: String::from("C:\\Documents\\Newsletters\\Summer2018.pdf"), relative: String::from("Newsletters\\Summer2018.pdf"), - positions: vec![7, 8, 15], + positions: VecDeque::from(vec![7, 8, 15]), depth: 1, }, ); @@ -179,7 +174,7 @@ mod tests { MatchedPath { absolute: String::from("\\Folder\\foo\\bar\\☕.txt"), relative: String::from("foo\\bar\\☕.txt"), - positions: vec![0, 1, 2, 8, 12], + positions: VecDeque::from(vec![0, 1, 2, 8, 12]), depth: 2, }, ); @@ -189,7 +184,6 @@ mod tests { fn returns_fields() { let path = new("abc", "/home", "/home/abc.txt"); assert_eq!(path.relative(), "abc.txt"); - assert_eq!(path.positions(), vec![0, 1, 2]); } #[test]