aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel <kingdread@gmx.de>2018-09-07 01:55:57 +0200
committerDaniel <kingdread@gmx.de>2018-09-07 01:55:57 +0200
commite8cb7b30474cb873c036ab5b7d7cb075f38a5018 (patch)
treeb3ac1154d3660ad806ce1ff4fdeeb3c9f0b44c6f
parent198a2d11fdeb0d1bac0f75db7535776a6709e124 (diff)
downloadraidgrep-e8cb7b30474cb873c036ab5b7d7cb075f38a5018.tar.gz
raidgrep-e8cb7b30474cb873c036ab5b7d7cb075f38a5018.tar.bz2
raidgrep-e8cb7b30474cb873c036ab5b7d7cb075f38a5018.zip
more readability for SearchField checking
-rw-r--r--src/main.rs20
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)));
}