diff options
author | Toby Vincent <tobyv13@gmail.com> | 2022-11-17 23:12:10 -0600 |
---|---|---|
committer | Toby Vincent <tobyv13@gmail.com> | 2022-11-17 23:12:10 -0600 |
commit | 09be0362d42034e343b64de08618c995b63c90fe (patch) | |
tree | 23f44d4e36cd767ea86f524db6016d64819eaf9b /src/paths.rs | |
parent | 082d11db68efa63f6da1be29cc9dc95b8f9e1735 (diff) |
feat: get intitial finder working
Diffstat (limited to 'src/paths.rs')
-rw-r--r-- | src/paths.rs | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/paths.rs b/src/paths.rs index 8f0153c..d9c1214 100644 --- a/src/paths.rs +++ b/src/paths.rs @@ -1,9 +1,10 @@ +use figment::Provider; use ignore::{Walk, WalkBuilder}; use std::{path::PathBuf, vec::IntoIter}; use tracing::warn; pub use config::{Config, PathEntry}; -pub use error::Error; +pub use error::{Error, Result}; mod config; mod error; @@ -14,17 +15,30 @@ pub struct Paths { } impl Paths { - pub fn new(path_entries: Vec<PathEntry>) -> Self { + pub fn new() -> Result<Self> { + Self::from_provider(Config::figment()) + } + + /// Extract `Config` from `provider` to construct new `Paths` + pub fn from_provider<T: Provider>(provider: T) -> Result<Self> { + Config::extract(&provider) + .map_err(Into::into) + .map(Into::into) + } +} + +impl From<Vec<PathEntry>> for Paths { + fn from(value: Vec<PathEntry>) -> Self { Self { - paths_iter: path_entries.into_iter(), + paths_iter: value.into_iter(), iter: None, } } } -impl From<&Config> for Paths { - fn from(value: &Config) -> Self { - Self::new(value.paths.to_owned()) +impl From<Config> for Paths { + fn from(value: Config) -> Self { + value.paths.into() } } |