summaryrefslogtreecommitdiffstats
path: root/src/project.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/project.rs')
-rw-r--r--src/project.rs57
1 files changed, 11 insertions, 46 deletions
diff --git a/src/project.rs b/src/project.rs
index 2b3e028..b71a3b8 100644
--- a/src/project.rs
+++ b/src/project.rs
@@ -1,58 +1,23 @@
use std::{
- ops::{Deref, DerefMut},
+ convert::Infallible,
path::PathBuf,
time::{Duration, SystemTime},
};
-use tracing::warn;
+pub trait Generator {
+ type Error: std::error::Error;
-pub mod path;
-
-#[cfg(feature = "git")]
-pub mod git;
-
-pub trait ProjectParser {
- fn parse(&self, path_buf: PathBuf) -> Result<Project, Box<dyn std::error::Error>>;
-}
-
-#[derive(Default)]
-pub struct ProjectParserGroup {
- pub parsers: Vec<Box<dyn ProjectParser>>,
+ fn generate(self) -> Result<Vec<Project>, Self::Error>;
}
-impl ProjectParserGroup {
- pub fn new() -> Self {
- Self::default()
- }
-
- pub fn parse(&self, path_buf: std::path::PathBuf) -> Option<Project> {
- if self.parsers.is_empty() {
- return path_buf.try_into().ok();
- }
-
- self.iter()
- .map(|p| p.parse(path_buf.to_owned()))
- .inspect(|res| {
- if let Err(err) = res {
- warn!(%err, "Parser failed to match");
- }
- })
- .flatten()
- .reduce(|max, p| p.max(max))
- }
-}
-
-impl Deref for ProjectParserGroup {
- type Target = Vec<Box<dyn ProjectParser>>;
-
- fn deref(&self) -> &Self::Target {
- &self.parsers
- }
-}
+impl<T> Generator for T
+where
+ T: IntoIterator<Item = Project>,
+{
+ type Error = Infallible;
-impl DerefMut for ProjectParserGroup {
- fn deref_mut(&mut self) -> &mut Self::Target {
- &mut self.parsers
+ fn generate(self) -> Result<Vec<Project>, Self::Error> {
+ Ok(self.into_iter().collect())
}
}