From d9b7433d168f3a5254e9bd10efd8c2875a3ff366 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 9 Apr 2020 12:26:06 +0200 Subject: replace unwrap/match with if-let --- src/filters.rs | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/filters.rs b/src/filters.rs index 715e4e4..cdd8f36 100644 --- a/src/filters.rs +++ b/src/filters.rs @@ -1,10 +1,10 @@ -use evtclib::{Agent, AgentName}; use evtclib::raw::parser::PartialEvtc; use evtclib::statistics::gamedata::Boss; +use evtclib::{Agent, AgentName}; use num_traits::FromPrimitive; -use super::{SearchField, LogResult, Opt, guilds}; +use super::{guilds, LogResult, Opt, SearchField}; use chrono::Datelike; @@ -12,22 +12,18 @@ use chrono::Datelike; pub fn filter_name(evtc: &PartialEvtc, opt: &Opt) -> bool { for player in &evtc.agents { let fancy = Agent::from_raw(player); - if fancy.is_err() { - continue; - } - match fancy.unwrap().name() { - AgentName::Player { - ref account_name, - ref character_name, - .. - } => { - if (opt.field.contains(&SearchField::Account) && opt.expression.is_match(account_name)) - || (opt.field.contains(&SearchField::Character) && opt.expression.is_match(character_name)) - { - return true; - } + if let Ok(AgentName::Player { + ref account_name, + ref character_name, + .. + }) = fancy.as_ref().map(Agent::name) + { + if (opt.field.contains(&SearchField::Account) && opt.expression.is_match(account_name)) + || (opt.field.contains(&SearchField::Character) + && opt.expression.is_match(character_name)) + { + return true; } - _ => (), } } // Don't throw away the log yet if we are searching for guilds @@ -37,9 +33,7 @@ pub fn filter_name(evtc: &PartialEvtc, opt: &Opt) -> bool { /// Do filtering based on the boss ID. pub fn filter_boss(evtc: &PartialEvtc, opt: &Opt) -> bool { let boss = Boss::from_u16(evtc.header.combat_id); - boss - .map(|b| opt.bosses.contains(&b)) - .unwrap_or(true) + boss.map(|b| opt.bosses.contains(&b)).unwrap_or(true) } /// Do filtering based on the fight outcome. -- cgit v1.2.3