Refactoring: Use function chaining rather than matching

This commit is contained in:
Matthias Beyer 2018-01-04 23:09:30 +01:00
parent 5db3d0c278
commit c92e459e3a
4 changed files with 10 additions and 36 deletions

View file

@ -52,12 +52,7 @@ impl<P: Predicate> Filter<Entry> for FieldPredicate<P> {
fn filter(&self, e: &Entry) -> bool {
e.get_header()
.read(&self.header_field_path[..])
.map(|val| {
match val {
None => false,
Some(v) => (*self.predicate).evaluate(v),
}
})
.map(|val| val.map(|v| (*self.predicate).evaluate(v)).unwrap_or(false))
.unwrap_or(false)
}

View file

@ -18,7 +18,6 @@
//
use semver::Version;
use toml::Value;
use libimagstore::store::Entry;
@ -44,15 +43,9 @@ impl Filter<Entry> for VersionEq {
.read("imag.version")
.map(|val| {
val.map_or(false, |v| {
match *v {
Value::String(ref s) => {
match Version::parse(&s[..]) {
Ok(v) => v == self.version,
_ => false
}
},
_ => false,
}
v.as_str()
.map(|s| Version::parse(s).map(|v| v == self.version).unwrap_or(false))
.unwrap_or(false)
})
})
.unwrap_or(false)

View file

@ -18,7 +18,6 @@
//
use semver::Version;
use toml::Value;
use libimagstore::store::Entry;
@ -44,15 +43,9 @@ impl Filter<Entry> for VersionGt {
.read("imag.version")
.map(|val| {
val.map_or(false, |v| {
match *v {
Value::String(ref s) => {
match Version::parse(&s[..]) {
Ok(v) => v > self.version,
_ => false
}
},
_ => false,
}
v.as_str()
.map(|s| Version::parse(s).map(|v| v > self.version).unwrap_or(false))
.unwrap_or(false)
})
})
.unwrap_or(false)

View file

@ -18,7 +18,6 @@
//
use semver::Version;
use toml::Value;
use libimagstore::store::Entry;
@ -44,15 +43,9 @@ impl Filter<Entry> for VersionLt {
.read("imag.version")
.map(|val| {
val.map_or(false, |v| {
match *v {
Value::String(ref s) => {
match Version::parse(&s[..]) {
Ok(v) => v < self.version,
_ => false
}
},
_ => false,
}
v.as_str()
.map(|s| Version::parse(s).map(|v| v < self.version).unwrap_or(false))
.unwrap_or(false)
})
})
.unwrap_or(false)