aboutsummaryrefslogtreecommitdiffstats
path: root/src/search.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/search.rs')
-rw-r--r--src/search.rs33
1 files changed, 14 insertions, 19 deletions
diff --git a/src/search.rs b/src/search.rs
index e39d67b..65fd295 100644
--- a/src/search.rs
+++ b/src/search.rs
@@ -1,12 +1,14 @@
use figment::Provider;
use std::vec::IntoIter;
-use crate::{Config, Project, Result};
+use crate::{Config, Result};
pub use entry::Entry;
pub mod entry;
+type ProjectItem = Box<dyn crate::Project<Error = crate::project::Error>>;
+
pub struct Search {
iter: IntoIter<entry::Config>,
curr: Option<Entry>,
@@ -33,20 +35,11 @@ impl Search {
}
}
-// impl<T> From<T> for Search
-// where
-// T: IntoIterator<Item = entry::Config, IntoIter = IntoIter<entry::Config>>,
-// {
-// fn from(value: T) -> Self {
-// Self {
-// iter: value.into_iter(),
-// curr: None,
-// }
-// }
-// }
-
-impl From<Vec<entry::Config>> for Search {
- fn from(value: Vec<entry::Config>) -> Self {
+impl<T> From<T> for Search
+where
+ T: IntoIterator<IntoIter = IntoIter<entry::Config>>,
+{
+ fn from(value: T) -> Self {
Self {
iter: value.into_iter(),
curr: None,
@@ -61,7 +54,7 @@ impl From<Config> for Search {
}
impl Iterator for Search {
- type Item = Box<dyn Project>;
+ type Item = ProjectItem;
#[tracing::instrument]
fn next(&mut self) -> Option<Self::Item> {
@@ -117,11 +110,13 @@ mod tests {
path_bufs.iter().try_for_each(fs::create_dir_all).unwrap();
path_bufs.sort();
- let mut results = paths.into_iter().collect::<Vec<Box<dyn Project>>>();
- results.sort_unstable_by_key(|p| p.timestamp());
+ let mut results = paths.into_iter().collect::<Vec<ProjectItem>>();
+
+ results.sort_unstable_by_key(|p| p.timestamp().unwrap_or_default());
+
let results = results
.into_iter()
- .map(|p| p.to_path_buf())
+ .map(|p| p.to_path_buf().to_owned())
.collect::<Vec<PathBuf>>();
assert_eq!(path_bufs, results);