From e8cb7b30474cb873c036ab5b7d7cb075f38a5018 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 7 Sep 2018 01:55:57 +0200 Subject: more readability for SearchField checking --- src/main.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index b366a17..3246864 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,6 +62,20 @@ enum SearchField { Character, } +impl SearchField { + /// True if the state says that the account name should be searched. + #[inline] + fn search_account(&self) -> bool { + *self == SearchField::All || *self == SearchField::Account + } + + /// True if the state says that the character name should be searched. + #[inline] + fn search_character(&self) -> bool { + *self == SearchField::All || *self == SearchField::Character + } +} + impl FromStr for SearchField { type Err = &'static str; @@ -176,10 +190,8 @@ fn search_log(entry: &DirEntry, opt: &Opt) -> Result, RuntimeE character_name, .. } => { - if ((opt.field == SearchField::All || opt.field == SearchField::Account) - && opt.expression.is_match(account_name)) - || ((opt.field == SearchField::All || opt.field == SearchField::Character) - && opt.expression.is_match(character_name)) + if (opt.field.search_account() && opt.expression.is_match(account_name)) + || (opt.field.search_character() && opt.expression.is_match(character_name)) { return Ok(Some(extract_info(entry, &log))); } -- cgit v1.2.3