summaryrefslogtreecommitdiffstats
path: root/libimagentryfilter
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-03-12 15:05:09 +0100
committerMatthias Beyer <mail@beyermatthias.de>2016-03-12 15:06:34 +0100
commit564d8d84fe7ad555eb5d58d834b8ee49f2c24440 (patch)
tree683be911a493558f7ca2058d8c717e3ca8b5a61e /libimagentryfilter
parentf86a8968a4ff93eefd470f4cf381d03978662898 (diff)
Reimplement FieldIsType filter with FieldPredicate filter
Diffstat (limited to 'libimagentryfilter')
-rw-r--r--libimagentryfilter/src/builtin/header/field_istype.rs25
1 files changed, 17 insertions, 8 deletions
diff --git a/libimagentryfilter/src/builtin/header/field_istype.rs b/libimagentryfilter/src/builtin/header/field_istype.rs
index 6ff6d511..8423c0ab 100644
--- a/libimagentryfilter/src/builtin/header/field_istype.rs
+++ b/libimagentryfilter/src/builtin/header/field_istype.rs
@@ -1,6 +1,8 @@
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;
@@ -31,17 +33,27 @@ impl Type {
}
+struct IsTypePred {
+ ty: Type
+}
+
+impl Predicate for IsTypePred {
+
+ fn evaluate(&self, v: Value) -> bool {
+ self.ty.matches(&v)
+ }
+
+}
+
pub struct FieldIsType {
- header_field_path: FieldPath,
- expected_type: Type,
+ filter: FieldPredicate<IsTypePred>,
}
impl FieldIsType {
pub fn new(path: FieldPath, expected_type: Type) -> FieldIsType {
FieldIsType {
- header_field_path: path,
- expected_type: expected_type,
+ filter: FieldPredicate::new(path, Box::new(IsTypePred { ty: expected_type })),
}
}
@@ -50,10 +62,7 @@ impl FieldIsType {
impl Filter for FieldIsType {
fn filter(&self, e: &Entry) -> bool {
- e.get_header()
- .read(&self.header_field_path[..])
- .map(|val| val.map(|v| self.expected_type.matches(&v)).unwrap_or(false))
- .unwrap_or(false)
+ self.filter.filter(e)
}
}