diff --git a/libimagentryfilter/src/builtin/header/field_eq.rs b/libimagentryfilter/src/builtin/header/field_eq.rs index 5617a42b..eeef5aa7 100644 --- a/libimagentryfilter/src/builtin/header/field_eq.rs +++ b/libimagentryfilter/src/builtin/header/field_eq.rs @@ -1,22 +1,34 @@ use libimagstore::store::Entry; use builtin::header::field_path::FieldPath; +use builtin::header::field_predicate::FieldPredicate; +use builtin::header::field_predicate::Predicate; use filter::Filter; use toml::Value; +struct EqPred { + expected: Value +} + +impl Predicate for EqPred { + + fn evaluate(&self, v: Value) -> bool { + self.expected == v + } + +} + /// Check whether certain header field in a entry is equal to a value pub struct FieldEq { - header_field_path: FieldPath, - expected_value: Value + filter: FieldPredicate, } impl FieldEq { pub fn new(path: FieldPath, expected_value: Value) -> FieldEq { FieldEq { - header_field_path: path, - expected_value: expected_value, + filter: FieldPredicate::new(path, Box::new(EqPred { expected: expected_value })), } } @@ -25,10 +37,7 @@ impl FieldEq { impl Filter for FieldEq { fn filter(&self, e: &Entry) -> bool { - e.get_header() - .read(&self.header_field_path[..]) - .map(|val| val.map(|v| v == self.expected_value).unwrap_or(false)) - .unwrap_or(false) + self.filter.filter(e) } }