summaryrefslogtreecommitdiffstats
path: root/src/path.rs
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2023-05-04 19:43:08 -0500
committerToby Vincent <tobyv13@gmail.com>2023-05-04 19:43:08 -0500
commit5da4fb25f9bb72771c7f2798daa6339be0bc3900 (patch)
treec30639c7a95e1d94baff498d247eed43fdb3728e /src/path.rs
parent589cd987217755e1da7acbc304c373a75a9f7db5 (diff)
refactor: join iterators into a single walk
Diffstat (limited to 'src/path.rs')
-rw-r--r--src/path.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/path.rs b/src/path.rs
new file mode 100644
index 0000000..05a9caa
--- /dev/null
+++ b/src/path.rs
@@ -0,0 +1,22 @@
+use std::{io::ErrorKind, path::PathBuf};
+
+use crate::{parser::Parser, project::Project};
+
+#[derive(Debug, Clone)]
+pub enum PathMatcher {
+ All,
+ Pattern(String),
+}
+
+impl Parser for PathMatcher {
+ #[tracing::instrument]
+ fn parse(&self, path_buf: PathBuf) -> Result<Project, Box<dyn std::error::Error>> {
+ let project = match self {
+ PathMatcher::All => path_buf.try_into()?,
+ PathMatcher::Pattern(p) if path_buf.join(p).exists() => path_buf.try_into()?,
+ _ => return Err(Box::new(std::io::Error::from(ErrorKind::NotFound))),
+ };
+
+ Ok(project)
+ }
+}