diff options
Diffstat (limited to 'lib/entry/libimagentryfilter')
13 files changed, 38 insertions, 34 deletions
diff --git a/lib/entry/libimagentryfilter/Cargo.toml b/lib/entry/libimagentryfilter/Cargo.toml index decdc730..ea4df09d 100644 --- a/lib/entry/libimagentryfilter/Cargo.toml +++ b/lib/entry/libimagentryfilter/Cargo.toml @@ -21,6 +21,7 @@ log = "0.3" regex = "0.2" semver = "0.5.*" toml = "^0.4" +toml-query = "0.3.0" libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } libimagentrytag = { version = "0.4.0", path = "../../../lib/entry/libimagentrytag" } diff --git a/lib/entry/libimagentryfilter/src/builtin/header/field_eq.rs b/lib/entry/libimagentryfilter/src/builtin/header/field_eq.rs index f10f3d0f..e2051958 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/field_eq.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/field_eq.rs @@ -32,8 +32,8 @@ struct EqPred { impl Predicate for EqPred { - fn evaluate(&self, v: Value) -> bool { - self.expected == v + fn evaluate(&self, v: &Value) -> bool { + self.expected == *v } } diff --git a/lib/entry/libimagentryfilter/src/builtin/header/field_exists.rs b/lib/entry/libimagentryfilter/src/builtin/header/field_exists.rs index 5fe672da..d793450a 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/field_exists.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/field_exists.rs @@ -18,11 +18,12 @@ // use libimagstore::store::Entry; -use libimagstore::toml_ext::TomlValueExt; -use builtin::header::field_path::FieldPath; +use toml_query::read::TomlValueReadExt; use filters::filter::Filter; +use builtin::header::field_path::FieldPath; + pub struct FieldExists { header_field_path: FieldPath, } diff --git a/lib/entry/libimagentryfilter/src/builtin/header/field_grep.rs b/lib/entry/libimagentryfilter/src/builtin/header/field_grep.rs index 799fee68..c6cdb624 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/field_grep.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/field_grep.rs @@ -33,10 +33,10 @@ struct EqGrep{ impl Predicate for EqGrep { - fn evaluate(&self, v: Value) -> bool { - match v { - Value::String(s) => self.regex.captures(&s[..]).is_some(), - _ => false, + fn evaluate(&self, v: &Value) -> bool { + match *v { + Value::String(ref s) => self.regex.captures(&s[..]).is_some(), + _ => false, } } diff --git a/lib/entry/libimagentryfilter/src/builtin/header/field_gt.rs b/lib/entry/libimagentryfilter/src/builtin/header/field_gt.rs index 2c1bcf89..6d50ddf7 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/field_gt.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/field_gt.rs @@ -32,17 +32,17 @@ struct EqGt { impl Predicate for EqGt { - fn evaluate(&self, v: Value) -> bool { + fn evaluate(&self, v: &Value) -> bool { match self.comp { Value::Integer(i) => { - match v { + match *v { Value::Integer(j) => i > j, Value::Float(f) => (i as f64) > f, _ => false, } }, Value::Float(f) => { - match v { + match *v { Value::Integer(i) => f > (i as f64), Value::Float(d) => f > d, _ => false, diff --git a/lib/entry/libimagentryfilter/src/builtin/header/field_isempty.rs b/lib/entry/libimagentryfilter/src/builtin/header/field_isempty.rs index 7a9c6521..57003e32 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/field_isempty.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/field_isempty.rs @@ -18,7 +18,7 @@ // use libimagstore::store::Entry; -use libimagstore::toml_ext::TomlValueExt; +use toml_query::read::TomlValueReadExt; use builtin::header::field_path::FieldPath; use filters::filter::Filter; @@ -46,12 +46,12 @@ impl Filter<Entry> for FieldIsEmpty { .read(&self.header_field_path[..]) .map(|v| { match v { - Some(Value::Array(a)) => a.is_empty(), - Some(Value::String(s)) => s.is_empty(), - Some(Value::Table(t)) => t.is_empty(), - Some(Value::Boolean(_)) | - Some(Value::Float(_)) | - Some(Value::Integer(_)) => false, + Some(&Value::Array(ref a)) => a.is_empty(), + Some(&Value::String(ref s)) => s.is_empty(), + Some(&Value::Table(ref t)) => t.is_empty(), + Some(&Value::Boolean(_)) | + Some(&Value::Float(_)) | + Some(&Value::Integer(_)) => false, _ => true, } }) diff --git a/lib/entry/libimagentryfilter/src/builtin/header/field_istype.rs b/lib/entry/libimagentryfilter/src/builtin/header/field_istype.rs index 889c8321..471f772f 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/field_istype.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/field_istype.rs @@ -58,8 +58,8 @@ struct IsTypePred { impl Predicate for IsTypePred { - fn evaluate(&self, v: Value) -> bool { - self.ty.matches(&v) + fn evaluate(&self, v: &Value) -> bool { + self.ty.matches(v) } } diff --git a/lib/entry/libimagentryfilter/src/builtin/header/field_lt.rs b/lib/entry/libimagentryfilter/src/builtin/header/field_lt.rs index 0316bf82..7a3e8445 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/field_lt.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/field_lt.rs @@ -32,17 +32,17 @@ struct EqLt { impl Predicate for EqLt { - fn evaluate(&self, v: Value) -> bool { + fn evaluate(&self, v: &Value) -> bool { match self.comp { Value::Integer(i) => { - match v { + match *v { Value::Integer(j) => i < j, Value::Float(f) => (i as f64) < f, _ => false, } }, Value::Float(f) => { - match v { + match *v { Value::Integer(i) => f < (i as f64), Value::Float(d) => f < d, _ => false, diff --git a/lib/entry/libimagentryfilter/src/builtin/header/field_predicate.rs b/lib/entry/libimagentryfilter/src/builtin/header/field_predicate.rs index 45aa332c..a167f762 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/field_predicate.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/field_predicate.rs @@ -18,7 +18,8 @@ // use libimagstore::store::Entry; -use libimagstore::toml_ext::TomlValueExt; + +use toml_query::read::TomlValueReadExt; use builtin::header::field_path::FieldPath; use filters::filter::Filter; @@ -26,7 +27,7 @@ use filters::filter::Filter; use toml::Value; pub trait Predicate { - fn evaluate(&self, Value) -> bool; + fn evaluate(&self, &Value) -> bool; } /// Check whether certain header field in a entry is equal to a value diff --git a/lib/entry/libimagentryfilter/src/builtin/header/version/eq.rs b/lib/entry/libimagentryfilter/src/builtin/header/version/eq.rs index 1ca38f8b..5ba9f306 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/version/eq.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/version/eq.rs @@ -21,8 +21,8 @@ use semver::Version; use toml::Value; use libimagstore::store::Entry; -use libimagstore::toml_ext::TomlValueExt; +use toml_query::read::TomlValueReadExt; use filters::filter::Filter; pub struct VersionEq { @@ -44,8 +44,8 @@ impl Filter<Entry> for VersionEq { .read("imag.version") .map(|val| { val.map_or(false, |v| { - match v { - Value::String(s) => { + match *v { + Value::String(ref s) => { match Version::parse(&s[..]) { Ok(v) => v == self.version, _ => false diff --git a/lib/entry/libimagentryfilter/src/builtin/header/version/gt.rs b/lib/entry/libimagentryfilter/src/builtin/header/version/gt.rs index 8e3873fb..edd0580f 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/version/gt.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/version/gt.rs @@ -21,8 +21,8 @@ use semver::Version; use toml::Value; use libimagstore::store::Entry; -use libimagstore::toml_ext::TomlValueExt; +use toml_query::read::TomlValueReadExt; use filters::filter::Filter; pub struct VersionGt { @@ -44,8 +44,8 @@ impl Filter<Entry> for VersionGt { .read("imag.version") .map(|val| { val.map_or(false, |v| { - match v { - Value::String(s) => { + match *v { + Value::String(ref s) => { match Version::parse(&s[..]) { Ok(v) => v > self.version, _ => false diff --git a/lib/entry/libimagentryfilter/src/builtin/header/version/lt.rs b/lib/entry/libimagentryfilter/src/builtin/header/version/lt.rs index c475b436..629be9ae 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/version/lt.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/version/lt.rs @@ -21,8 +21,8 @@ use semver::Version; use toml::Value; use libimagstore::store::Entry; -use libimagstore::toml_ext::TomlValueExt; +use toml_query::read::TomlValueReadExt; use filters::filter::Filter; pub struct VersionLt { @@ -44,8 +44,8 @@ impl Filter<Entry> for VersionLt { .read("imag.version") .map(|val| { val.map_or(false, |v| { - match v { - Value::String(s) => { + match *v { + Value::String(ref s) => { match Version::parse(&s[..]) { Ok(v) => v < self.version, _ => false diff --git a/lib/entry/libimagentryfilter/src/lib.rs b/lib/entry/libimagentryfilter/src/lib.rs index ad99db60..9f4fc84e 100644 --- a/lib/entry/libimagentryfilter/src/lib.rs +++ b/lib/entry/libimagentryfilter/src/lib.rs @@ -37,6 +37,7 @@ extern crate itertools; extern crate regex; extern crate semver; extern crate toml; +extern crate toml_query; extern crate libimagstore; extern crate libimagentrytag; |