diff --git a/libimagentryfilter/Cargo.toml b/libimagentryfilter/Cargo.toml index 0166dcb4..70ef4fcb 100644 --- a/libimagentryfilter/Cargo.toml +++ b/libimagentryfilter/Cargo.toml @@ -5,11 +5,12 @@ authors = ["Matthias Beyer "] [dependencies] clap = "2.*" +filters = "0.1.*" itertools = "0.4" log = "0.3" regex = "0.1" -toml = "0.2.*" semver = "0.2.1" +toml = "0.2.*" [dependencies.libimagstore] path = "../libimagstore" diff --git a/libimagentryfilter/src/builtin/bool_filter.rs b/libimagentryfilter/src/builtin/bool_filter.rs index 14dbbc8e..a25f8159 100644 --- a/libimagentryfilter/src/builtin/bool_filter.rs +++ b/libimagentryfilter/src/builtin/bool_filter.rs @@ -1,6 +1,6 @@ use libimagstore::store::Entry; -use filter::Filter; +use filters::filter::Filter; pub struct BoolFilter(bool); @@ -12,7 +12,7 @@ impl BoolFilter { } -impl Filter for BoolFilter { +impl Filter for BoolFilter { fn filter(&self, _: &Entry) -> bool { self.0 diff --git a/libimagentryfilter/src/builtin/content/grep.rs b/libimagentryfilter/src/builtin/content/grep.rs index f0bfb992..de8ade9b 100644 --- a/libimagentryfilter/src/builtin/content/grep.rs +++ b/libimagentryfilter/src/builtin/content/grep.rs @@ -1,10 +1,9 @@ +use filters::filter::Filter; use regex::Regex; use regex::Error as RError; use libimagstore::store::Entry; -use filter::Filter; - pub trait IntoRegex { fn into_regex(self) -> Result; @@ -44,7 +43,7 @@ impl ContentGrep { } -impl Filter for ContentGrep { +impl Filter for ContentGrep { fn filter(&self, e: &Entry) -> bool { self.regex.captures(&e.get_content()[..]).is_some() diff --git a/libimagentryfilter/src/builtin/content/length/is_over.rs b/libimagentryfilter/src/builtin/content/length/is_over.rs index 9190b01b..1ef51ab9 100644 --- a/libimagentryfilter/src/builtin/content/length/is_over.rs +++ b/libimagentryfilter/src/builtin/content/length/is_over.rs @@ -1,7 +1,6 @@ +use filters::filter::Filter; use libimagstore::store::Entry; -use filter::Filter; - pub struct ContentLengthIsOver { val: usize } @@ -16,7 +15,7 @@ impl ContentLengthIsOver { } -impl Filter for ContentLengthIsOver { +impl Filter for ContentLengthIsOver { fn filter(&self, e: &Entry) -> bool { e.get_content().len() > self.val diff --git a/libimagentryfilter/src/builtin/content/length/is_under.rs b/libimagentryfilter/src/builtin/content/length/is_under.rs index cca857da..5ae7fe7f 100644 --- a/libimagentryfilter/src/builtin/content/length/is_under.rs +++ b/libimagentryfilter/src/builtin/content/length/is_under.rs @@ -1,7 +1,6 @@ +use filters::filter::Filter; use libimagstore::store::Entry; -use filter::Filter; - pub struct ContentLengthIsUnder { val: usize } @@ -16,7 +15,7 @@ impl ContentLengthIsUnder { } -impl Filter for ContentLengthIsUnder { +impl Filter for ContentLengthIsUnder { fn filter(&self, e: &Entry) -> bool { e.get_content().len() < self.val diff --git a/libimagentryfilter/src/builtin/header/field_eq.rs b/libimagentryfilter/src/builtin/header/field_eq.rs index eeef5aa7..457f42b0 100644 --- a/libimagentryfilter/src/builtin/header/field_eq.rs +++ b/libimagentryfilter/src/builtin/header/field_eq.rs @@ -3,7 +3,7 @@ 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 filters::filter::Filter; use toml::Value; @@ -34,7 +34,7 @@ impl FieldEq { } -impl Filter for FieldEq { +impl Filter for FieldEq { fn filter(&self, e: &Entry) -> bool { self.filter.filter(e) diff --git a/libimagentryfilter/src/builtin/header/field_exists.rs b/libimagentryfilter/src/builtin/header/field_exists.rs index 98b3d691..721b7e0e 100644 --- a/libimagentryfilter/src/builtin/header/field_exists.rs +++ b/libimagentryfilter/src/builtin/header/field_exists.rs @@ -1,7 +1,7 @@ use libimagstore::store::Entry; use builtin::header::field_path::FieldPath; -use filter::Filter; +use filters::filter::Filter; pub struct FieldExists { header_field_path: FieldPath, @@ -17,7 +17,7 @@ impl FieldExists { } -impl Filter for FieldExists { +impl Filter for FieldExists { fn filter(&self, e: &Entry) -> bool { e.get_header().read(&self.header_field_path[..]).is_ok() diff --git a/libimagentryfilter/src/builtin/header/field_grep.rs b/libimagentryfilter/src/builtin/header/field_grep.rs index aac42207..ce312b02 100644 --- a/libimagentryfilter/src/builtin/header/field_grep.rs +++ b/libimagentryfilter/src/builtin/header/field_grep.rs @@ -6,7 +6,7 @@ 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 filters::filter::Filter; struct EqGrep{ regex: Regex @@ -38,7 +38,7 @@ impl FieldGrep { } -impl Filter for FieldGrep { +impl Filter for FieldGrep { fn filter(&self, e: &Entry) -> bool { self.filter.filter(e) diff --git a/libimagentryfilter/src/builtin/header/field_gt.rs b/libimagentryfilter/src/builtin/header/field_gt.rs index 7067399d..02786901 100644 --- a/libimagentryfilter/src/builtin/header/field_gt.rs +++ b/libimagentryfilter/src/builtin/header/field_gt.rs @@ -3,7 +3,7 @@ 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 filters::filter::Filter; use toml::Value; @@ -50,7 +50,7 @@ impl FieldGt { } -impl Filter for FieldGt { +impl Filter for FieldGt { fn filter(&self, e: &Entry) -> bool { self.filter.filter(e) diff --git a/libimagentryfilter/src/builtin/header/field_isempty.rs b/libimagentryfilter/src/builtin/header/field_isempty.rs index 3da9360f..e8ea94c3 100644 --- a/libimagentryfilter/src/builtin/header/field_isempty.rs +++ b/libimagentryfilter/src/builtin/header/field_isempty.rs @@ -1,7 +1,7 @@ use libimagstore::store::Entry; use builtin::header::field_path::FieldPath; -use filter::Filter; +use filters::filter::Filter; use toml::Value; @@ -19,7 +19,7 @@ impl FieldIsEmpty { } -impl Filter for FieldIsEmpty { +impl Filter for FieldIsEmpty { fn filter(&self, e: &Entry) -> bool { e.get_header() diff --git a/libimagentryfilter/src/builtin/header/field_istype.rs b/libimagentryfilter/src/builtin/header/field_istype.rs index 5af73623..13e6b325 100644 --- a/libimagentryfilter/src/builtin/header/field_istype.rs +++ b/libimagentryfilter/src/builtin/header/field_istype.rs @@ -3,7 +3,7 @@ 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 filters::filter::Filter; use toml::Value; @@ -59,7 +59,7 @@ impl FieldIsType { } -impl Filter for FieldIsType { +impl Filter for FieldIsType { fn filter(&self, e: &Entry) -> bool { self.filter.filter(e) diff --git a/libimagentryfilter/src/builtin/header/field_lt.rs b/libimagentryfilter/src/builtin/header/field_lt.rs index dee98476..9f6fae9a 100644 --- a/libimagentryfilter/src/builtin/header/field_lt.rs +++ b/libimagentryfilter/src/builtin/header/field_lt.rs @@ -3,7 +3,7 @@ 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 filters::filter::Filter; use toml::Value; @@ -50,7 +50,7 @@ impl FieldLt { } -impl Filter for FieldLt { +impl Filter for FieldLt { fn filter(&self, e: &Entry) -> bool { self.filter.filter(e) diff --git a/libimagentryfilter/src/builtin/header/field_predicate.rs b/libimagentryfilter/src/builtin/header/field_predicate.rs index 5dddc46e..1415b901 100644 --- a/libimagentryfilter/src/builtin/header/field_predicate.rs +++ b/libimagentryfilter/src/builtin/header/field_predicate.rs @@ -1,7 +1,7 @@ use libimagstore::store::Entry; use builtin::header::field_path::FieldPath; -use filter::Filter; +use filters::filter::Filter; use toml::Value; @@ -26,7 +26,7 @@ impl FieldPredicate

{ } -impl Filter for FieldPredicate

{ +impl Filter for FieldPredicate

{ fn filter(&self, e: &Entry) -> bool { e.get_header() diff --git a/libimagentryfilter/src/builtin/header/version/eq.rs b/libimagentryfilter/src/builtin/header/version/eq.rs index e6b93893..acf75495 100644 --- a/libimagentryfilter/src/builtin/header/version/eq.rs +++ b/libimagentryfilter/src/builtin/header/version/eq.rs @@ -3,7 +3,7 @@ use toml::Value; use libimagstore::store::Entry; -use filter::Filter; +use filters::filter::Filter; pub struct VersionEq { version: Version, @@ -17,7 +17,7 @@ impl VersionEq { } -impl Filter for VersionEq { +impl Filter for VersionEq { fn filter(&self, e: &Entry) -> bool { e.get_header() diff --git a/libimagentryfilter/src/builtin/header/version/gt.rs b/libimagentryfilter/src/builtin/header/version/gt.rs index f03b0fa9..cc5dcade 100644 --- a/libimagentryfilter/src/builtin/header/version/gt.rs +++ b/libimagentryfilter/src/builtin/header/version/gt.rs @@ -3,7 +3,7 @@ use toml::Value; use libimagstore::store::Entry; -use filter::Filter; +use filters::filter::Filter; pub struct VersionGt { version: Version, @@ -17,7 +17,7 @@ impl VersionGt { } -impl Filter for VersionGt { +impl Filter for VersionGt { fn filter(&self, e: &Entry) -> bool { e.get_header() diff --git a/libimagentryfilter/src/builtin/header/version/lt.rs b/libimagentryfilter/src/builtin/header/version/lt.rs index 5be6a191..b7232c4c 100644 --- a/libimagentryfilter/src/builtin/header/version/lt.rs +++ b/libimagentryfilter/src/builtin/header/version/lt.rs @@ -3,7 +3,7 @@ use toml::Value; use libimagstore::store::Entry; -use filter::Filter; +use filters::filter::Filter; pub struct VersionLt { version: Version, @@ -17,7 +17,7 @@ impl VersionLt { } -impl Filter for VersionLt { +impl Filter for VersionLt { fn filter(&self, e: &Entry) -> bool { e.get_header() diff --git a/libimagentryfilter/src/builtin/header/version/range.rs b/libimagentryfilter/src/builtin/header/version/range.rs index 9dffe5d6..66ccbcd8 100644 --- a/libimagentryfilter/src/builtin/header/version/range.rs +++ b/libimagentryfilter/src/builtin/header/version/range.rs @@ -4,23 +4,23 @@ use libimagstore::store::Entry; use builtin::header::version::gt::VersionGt; use builtin::header::version::lt::VersionLt; -use filter::Filter; -use ops::and::And; -use ops::not::Not; +use filters::filter::Filter; +use filters::ops::and::And; +use filters::ops::not::Not; pub struct VersionInRange { - and: And, + and: And, } impl VersionInRange { pub fn new(lowerbound: Version, upperbound: Version) -> VersionInRange { - VersionInRange { and: VersionGt::new(lowerbound).and(Box::new(VersionLt::new(upperbound))) } + VersionInRange { and: VersionGt::new(lowerbound).and(VersionLt::new(upperbound)) } } } -impl Filter for VersionInRange { +impl Filter for VersionInRange { fn filter(&self, e: &Entry) -> bool { self.and.filter(e) @@ -29,7 +29,7 @@ impl Filter for VersionInRange { } pub struct VersionOutOfRange { - not: Not + not: Not } impl VersionOutOfRange { @@ -40,7 +40,7 @@ impl VersionOutOfRange { } -impl Filter for VersionOutOfRange { +impl Filter for VersionOutOfRange { fn filter(&self, e: &Entry) -> bool { self.not.filter(e) diff --git a/libimagentryfilter/src/filter.rs b/libimagentryfilter/src/filter.rs deleted file mode 100644 index 2d0015a1..00000000 --- a/libimagentryfilter/src/filter.rs +++ /dev/null @@ -1,54 +0,0 @@ -use libimagstore::store::Entry; - -pub use ops::and::And; -pub use ops::not::Not; -pub use ops::or::Or; - -pub trait Filter { - - fn filter(&self, &Entry) -> bool; - - fn not(self) -> Not - where Self: Sized + 'static - { - Not::new(Box::new(self)) - } - - fn or(self, other: Box) -> Or - where Self: Sized + 'static - { - Or::new(Box::new(self), other) - } - - fn or_not(self, other: Box) -> Or - where Self: Sized + 'static - { - self.or(Box::new(Not::new(other))) - } - - fn or3(self, other: Box, other2: Box) -> Or - where Self: Sized + 'static - { - Or::new(Box::new(self), Box::new(Or::new(other, other2))) - } - - fn and(self, other: Box) -> And - where Self: Sized + 'static - { - And::new(Box::new(self), other) - } - - fn and3(self, other: Box, other2: Box) -> And - where Self: Sized + 'static - { - And::new(Box::new(self), Box::new(And::new(other, other2))) - } - - fn and_not(self, other: Box) -> And - where Self: Sized + 'static - { - self.and(Box::new(Not::new(other))) - } - -} - diff --git a/libimagentryfilter/src/lib.rs b/libimagentryfilter/src/lib.rs index e76d3a32..03cb114d 100644 --- a/libimagentryfilter/src/lib.rs +++ b/libimagentryfilter/src/lib.rs @@ -15,10 +15,11 @@ #[macro_use] extern crate log; +extern crate filters; extern crate itertools; extern crate regex; -extern crate toml; extern crate semver; +extern crate toml; extern crate libimagstore; extern crate libimagentrytag; @@ -28,8 +29,6 @@ extern crate libimagentrytag; pub mod cli; pub mod builtin; -pub mod filter; -pub mod ops; // extended functionality of the crate // these depend on other internal libraries than libimagstore and use the upper core modules for diff --git a/libimagentryfilter/src/ops/and.rs b/libimagentryfilter/src/ops/and.rs deleted file mode 100644 index 79470b9b..00000000 --- a/libimagentryfilter/src/ops/and.rs +++ /dev/null @@ -1,24 +0,0 @@ -use libimagstore::store::Entry; - -use filter::Filter; - -pub struct And { - a: Box, - b: Box -} - -impl And { - - pub fn new(a: Box, b: Box) -> And { - And { a: a, b: b } - } - -} - -impl Filter for And { - - fn filter(&self, e: &Entry) -> bool { - self.a.filter(e) && self.b.filter(e) - } - -} diff --git a/libimagentryfilter/src/ops/mod.rs b/libimagentryfilter/src/ops/mod.rs deleted file mode 100644 index 668eedc5..00000000 --- a/libimagentryfilter/src/ops/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod and; -pub mod not; -pub mod or; diff --git a/libimagentryfilter/src/ops/not.rs b/libimagentryfilter/src/ops/not.rs deleted file mode 100644 index a709d95b..00000000 --- a/libimagentryfilter/src/ops/not.rs +++ /dev/null @@ -1,23 +0,0 @@ -use libimagstore::store::Entry; - -use filter::Filter; - -pub struct Not { - a: Box -} - -impl Not { - - pub fn new(a: Box) -> Not { - Not { a: a } - } - -} - -impl Filter for Not { - - fn filter(&self, e: &Entry) -> bool { - !self.a.filter(e) - } - -} diff --git a/libimagentryfilter/src/ops/or.rs b/libimagentryfilter/src/ops/or.rs deleted file mode 100644 index e2ca810b..00000000 --- a/libimagentryfilter/src/ops/or.rs +++ /dev/null @@ -1,24 +0,0 @@ -use libimagstore::store::Entry; - -use filter::Filter; - -pub struct Or { - a: Box, - b: Box -} - -impl Or { - - pub fn new(a: Box, b: Box) -> Or { - Or { a: a, b: b } - } - -} - -impl Filter for Or { - - fn filter(&self, e: &Entry) -> bool { - self.a.filter(e) || self.b.filter(e) - } - -} diff --git a/libimagentryfilter/src/tags/mod.rs b/libimagentryfilter/src/tags/mod.rs index 8c2d2b4f..162e9824 100644 --- a/libimagentryfilter/src/tags/mod.rs +++ b/libimagentryfilter/src/tags/mod.rs @@ -2,7 +2,7 @@ use libimagstore::store::Entry; use libimagentrytag::tagable::Tagable; use libimagentrytag::tag::Tag; -use filter::Filter; +use filters::filter::Filter; /// Check whether an Entry has a certain tag pub struct HasTag { @@ -19,7 +19,7 @@ impl HasTag { } -impl Filter for HasTag { +impl Filter for HasTag { fn filter(&self, e: &Entry) -> bool { e.has_tag(&self.tag).ok().unwrap_or(false) @@ -43,7 +43,7 @@ impl HasAllTags { } -impl Filter for HasAllTags { +impl Filter for HasAllTags { fn filter(&self, e: &Entry) -> bool { e.has_tags(&self.tags).ok().unwrap_or(false) @@ -67,7 +67,7 @@ impl HasAnyTags { } -impl Filter for HasAnyTags { +impl Filter for HasAnyTags { fn filter(&self, e: &Entry) -> bool { self.tags.iter().any(|tag| e.has_tag(tag).ok().unwrap_or(false))