diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/main.rs b/src/main.rs index 41df732..bea03f6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +#![feature(trait_alias)] use std::collections::HashMap; use std::fs::File; use std::io::{BufReader, Read, Seek}; @@ -15,7 +16,7 @@ use walkdir::{DirEntry, WalkDir}; use evtclib::{AgentKind, AgentName, EventKind, Log}; mod filters; -use filters::{Filter, Inclusion}; +use filters::{log::LogFilter, Inclusion}; mod guilds; mod logger; mod output; @@ -260,21 +261,24 @@ fn is_log_file(entry: &DirEntry) -> bool { .unwrap_or(false) } -fn build_filter(opt: &Opt) -> Box<dyn Filter> { - let mut filter = filters::Const::new(false); - for field in opt.field.values() { - filter = filter | filters::NameFilter::new(*field, opt.expression.clone()); - } +fn build_filter(opt: &Opt) -> Box<dyn LogFilter> { + let player_filter = opt + .field + .values() + .iter() + .map(|field| filters::player::NameFilter::new(*field, opt.expression.clone())) + .fold(filters::Const::new(false), |a, f| a | f); + let mut filter = filters::player::any(player_filter); if opt.invert { filter = !filter; } filter = filter - & filters::BossFilter::new(opt.bosses.values().clone()) - & filters::OutcomeFilter::new(opt.outcome.values().clone()) - & filters::WeekdayFilter::new(opt.weekdays.values().clone()) - & filters::TimeFilter::new(opt.after, opt.before); + & filters::log::BossFilter::new(opt.bosses.values().clone()) + & filters::log::OutcomeFilter::new(opt.outcome.values().clone()) + & filters::log::WeekdayFilter::new(opt.weekdays.values().clone()) + & filters::log::TimeFilter::new(opt.after, opt.before); filter } @@ -282,7 +286,7 @@ fn build_filter(opt: &Opt) -> Box<dyn Filter> { /// Run the grep search with the given options. fn grep(opt: &Opt) -> Result<()> { let pipeline = &output::build_pipeline(opt); - let filter: &dyn Filter = &*build_filter(opt); + let filter: &dyn LogFilter = &*build_filter(opt); rayon::scope(|s| { let walker = WalkDir::new(&opt.path); for entry in walker { @@ -309,7 +313,7 @@ fn grep(opt: &Opt) -> Result<()> { /// If the log matches, returns `Ok(Some(..))`. /// If the log doesn't match, returns `Ok(None)`. /// If there was a fatal error, returns `Err(..)`. -fn search_log(entry: &DirEntry, filter: &dyn Filter) -> Result<Option<LogResult>> { +fn search_log(entry: &DirEntry, filter: &dyn LogFilter) -> Result<Option<LogResult>> { let file_stream = BufReader::new(File::open(entry.path())?); let is_zip = entry .file_name() |