diff options
| -rw-r--r-- | src/main.rs | 20 | 
1 files 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<Option<LogResult>, 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)));                  } | 
