From 09be0362d42034e343b64de08618c995b63c90fe Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Thu, 17 Nov 2022 23:12:10 -0600 Subject: feat: get intitial finder working --- src/paths.rs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'src/paths.rs') 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) -> Self { + pub fn new() -> Result { + Self::from_provider(Config::figment()) + } + + /// Extract `Config` from `provider` to construct new `Paths` + pub fn from_provider(provider: T) -> Result { + Config::extract(&provider) + .map_err(Into::into) + .map(Into::into) + } +} + +impl From> for Paths { + fn from(value: Vec) -> 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 for Paths { + fn from(value: Config) -> Self { + value.paths.into() } } -- cgit v1.2.3-70-g09d2