libimagentryfilter: Replace read with typed read

This commit is contained in:
Matthias Beyer 2018-01-12 16:32:18 +01:00
parent 6c36c97895
commit 18a6e9b64e
3 changed files with 9 additions and 21 deletions

View file

@ -21,7 +21,7 @@ use semver::Version;
use libimagstore::store::Entry; use libimagstore::store::Entry;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt;
use filters::filter::Filter; use filters::filter::Filter;
pub struct VersionEq { pub struct VersionEq {
@ -40,13 +40,9 @@ impl Filter<Entry> for VersionEq {
fn filter(&self, e: &Entry) -> bool { fn filter(&self, e: &Entry) -> bool {
e.get_header() e.get_header()
.read("imag.version") .read_string("imag.version")
.map(|val| { .map(|val| {
val.map_or(false, |v| { val.map_or(false, |s| Version::parse(&s).map(|v| v == self.version).unwrap_or(false))
v.as_str()
.map(|s| Version::parse(s).map(|v| v == self.version).unwrap_or(false))
.unwrap_or(false)
})
}) })
.unwrap_or(false) .unwrap_or(false)
} }

View file

@ -21,7 +21,7 @@ use semver::Version;
use libimagstore::store::Entry; use libimagstore::store::Entry;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt;
use filters::filter::Filter; use filters::filter::Filter;
pub struct VersionGt { pub struct VersionGt {
@ -40,13 +40,9 @@ impl Filter<Entry> for VersionGt {
fn filter(&self, e: &Entry) -> bool { fn filter(&self, e: &Entry) -> bool {
e.get_header() e.get_header()
.read("imag.version") .read_string("imag.version")
.map(|val| { .map(|val| {
val.map_or(false, |v| { val.map_or(false, |s| Version::parse(&s).map(|v| v > self.version).unwrap_or(false))
v.as_str()
.map(|s| Version::parse(s).map(|v| v > self.version).unwrap_or(false))
.unwrap_or(false)
})
}) })
.unwrap_or(false) .unwrap_or(false)
} }

View file

@ -21,7 +21,7 @@ use semver::Version;
use libimagstore::store::Entry; use libimagstore::store::Entry;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt;
use filters::filter::Filter; use filters::filter::Filter;
pub struct VersionLt { pub struct VersionLt {
@ -40,13 +40,9 @@ impl Filter<Entry> for VersionLt {
fn filter(&self, e: &Entry) -> bool { fn filter(&self, e: &Entry) -> bool {
e.get_header() e.get_header()
.read("imag.version") .read_string("imag.version")
.map(|val| { .map(|val| {
val.map_or(false, |v| { val.map_or(false, |s| Version::parse(&s).map(|v| v < self.version).unwrap_or(false))
v.as_str()
.map(|s| Version::parse(s).map(|v| v < self.version).unwrap_or(false))
.unwrap_or(false)
})
}) })
.unwrap_or(false) .unwrap_or(false)
} }