diff options
author | Daniel <kingdread@gmx.de> | 2020-05-01 13:29:38 +0200 |
---|---|---|
committer | Daniel <kingdread@gmx.de> | 2020-05-01 13:29:38 +0200 |
commit | 5f765b749f793b2866262546d28ff138a5654dfc (patch) | |
tree | 192add4f0c51169f8f2702596d05bee00af6561a /src/main.rs | |
parent | 811d7e62695c5c12aecd08b176c4ead641e2ad2c (diff) | |
download | raidgrep-5f765b749f793b2866262546d28ff138a5654dfc.tar.gz raidgrep-5f765b749f793b2866262546d28ff138a5654dfc.tar.bz2 raidgrep-5f765b749f793b2866262546d28ff138a5654dfc.zip |
change LogFilter to take EarlyLogResult
This allows us to attach some additional metadata that is not found in
the PartialEvtc otherwise, such as the file name.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index db2a5e7..33b3c45 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ use std::path::PathBuf; use std::str::FromStr; use anyhow::{anyhow, Error, Result}; -use chrono::{DateTime, TimeZone, Utc, Weekday}; +use chrono::{DateTime, TimeZone, Utc}; use colored::Colorize; use itertools::Itertools; use log::debug; @@ -16,6 +16,7 @@ use rustyline::Editor; use structopt::StructOpt; use walkdir::{DirEntry, WalkDir}; +use evtclib::raw::parser::PartialEvtc; use evtclib::{EliteSpec, EventKind, Log, Profession}; mod fexpr; @@ -155,6 +156,17 @@ pub enum FightOutcome { Wipe, } +/// A stripped version of [`LogResult`][LogResult] that is available early in the parsing process. +/// +/// This can be used by filters to filter out logs early, before they will be fully parsed. +#[derive(Debug, Clone)] +pub struct EarlyLogResult { + /// The path to the log file. + log_file: PathBuf, + /// The partially parsed evtc. + evtc: PartialEvtc, +} + impl FromStr for FightOutcome { type Err = &'static str; @@ -368,7 +380,12 @@ fn search_log(entry: &DirEntry, filter: &dyn LogFilter) -> Result<Option<LogResu let mut stream = wrapper.get_stream(); let partial = evtclib::raw::parser::parse_partial_file(&mut stream)?; - let early_ok = filter.filter_early(&partial); + let early_log = EarlyLogResult { + log_file: entry.path().to_owned(), + evtc: partial, + }; + let early_ok = filter.filter_early(&early_log); + let partial = early_log.evtc; if early_ok == Inclusion::Exclude { return Ok(None); |