diff options
Diffstat (limited to 'src/search')
-rw-r--r-- | src/search/entry.rs | 17 | ||||
-rw-r--r-- | src/search/entry/config.rs | 84 |
2 files changed, 7 insertions, 94 deletions
diff --git a/src/search/entry.rs b/src/search/entry.rs index 6cd601c..9e58962 100644 --- a/src/search/entry.rs +++ b/src/search/entry.rs @@ -2,21 +2,18 @@ use ignore::{Walk, WalkBuilder}; use tracing::error; use crate::{ + config::Entry, project::{path::PathMatcher, ProjectParser, ProjectParserGroup}, search::ProjectItem, }; -pub use config::Config; - -mod config; - -pub struct Entry { +pub struct EntryIter { parsers: ProjectParserGroup, iter: Walk, } -impl Entry { - fn new(config: &Config) -> Self { +impl EntryIter { + fn new(config: &Entry) -> Self { let iter = WalkBuilder::new(&config.path_buf) .standard_filters(true) .max_depth(config.max_depth) @@ -38,13 +35,13 @@ impl Entry { } } -impl From<Config> for Entry { - fn from(config: Config) -> Self { +impl From<Entry> for EntryIter { + fn from(config: Entry) -> Self { Self::new(&config) } } -impl Iterator for Entry { +impl Iterator for EntryIter { type Item = ProjectItem; fn next(&mut self) -> Option<Self::Item> { diff --git a/src/search/entry/config.rs b/src/search/entry/config.rs deleted file mode 100644 index 4372356..0000000 --- a/src/search/entry/config.rs +++ /dev/null @@ -1,84 +0,0 @@ -use serde::{Deserialize, Deserializer, Serialize}; -use std::{convert::Infallible, path::PathBuf, str::FromStr}; - -#[derive(Debug, PartialEq, Eq, Clone, Default, Serialize)] -#[serde(default)] -pub struct Config { - pub path_buf: PathBuf, - pub hidden: bool, - pub max_depth: Option<usize>, - pub pattern: Option<String>, - - #[cfg(feature = "git")] - pub git: bool, -} - -impl From<PathBuf> for Config { - fn from(path_buf: PathBuf) -> Self { - Self { - path_buf, - ..Default::default() - } - } -} - -impl Config { - pub fn new(path_buf: PathBuf) -> Self { - Self { - path_buf, - ..Default::default() - } - } -} - -impl FromStr for Config { - type Err = Infallible; - - fn from_str(s: &str) -> Result<Self, Self::Err> { - s.parse().map(PathBuf::into) - } -} - -// Custom deserialize impl to accept either string or struct -impl<'de> Deserialize<'de> for Config { - fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> - where - D: Deserializer<'de>, - { - #[derive(Deserialize)] - #[serde(untagged)] - enum Variants { - String(String), - Struct { - path_buf: PathBuf, - hidden: bool, - max_depth: Option<usize>, - pattern: Option<String>, - - #[cfg(feature = "git")] - git: bool, - }, - } - - match Variants::deserialize(deserializer)? { - Variants::String(s) => s.parse().map_err(serde::de::Error::custom), - Variants::Struct { - path_buf, - hidden, - max_depth, - pattern, - - #[cfg(feature = "git")] - git, - } => Ok(Self { - path_buf, - hidden, - max_depth, - pattern, - - #[cfg(feature = "git")] - git, - }), - } - } -} |