use crate::{Testable, TestableCollection};
use glob_match::glob_match;
pub struct FileType<'a> {
pub pattern: &'a str,
}
impl FileType<'_> {
pub fn new(pattern: &str) -> FileType<'_> {
FileType { pattern }
}
pub fn applies(&self, file: &Testable) -> bool {
if let Some(basename) = file.basename() {
glob_match(self.pattern, &basename)
} else {
false
}
}
}
pub trait FileTypeConvert<'a, T: 'a> {
#[allow(clippy::wrong_self_convention)]
fn from_testable(&self, t: &'a Testable) -> Option<T>;
#[allow(clippy::wrong_self_convention)]
fn from_collection(&self, t: &'a TestableCollection) -> Vec<T> {
t.iter().filter_map(|f| self.from_testable(f)).collect()
}
}