use std::path::PathBuf; use crate::project::Project; pub trait Parser { type Error: std::error::Error; fn parse(&self, path_buf: PathBuf) -> Result; } pub trait FilterMap { fn filter_map(&self, path_buf: PathBuf) -> Option; } impl FilterMap for T where T: Parser, { fn filter_map(&self, path_buf: PathBuf) -> Option { match self.parse(path_buf) { Ok(p) => Some(p), Err(err) => { tracing::info!(%err, "Parser failed to parse project"); None } } } } impl FilterMap for Vec> { fn filter_map(&self, path_buf: PathBuf) -> Option { self.iter() .filter_map(|p| p.filter_map(path_buf.to_owned())) .reduce(|max, p| p.max(max)) } }