From 5da4fb25f9bb72771c7f2798daa6339be0bc3900 Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Thu, 4 May 2023 19:43:08 -0500 Subject: refactor: join iterators into a single walk --- src/path.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/path.rs (limited to 'src/path.rs') 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> { + 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) + } +} -- cgit v1.2.3-70-g09d2