From 98dde5d0d15588927c59623cd025a16fb5f53f10 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 15 Mar 2016 23:18:11 +0100 Subject: [PATCH] Add filter: VersionInRange, VersionOutOfRange --- .../src/builtin/header/version/mod.rs | 3 +- .../src/builtin/header/version/range.rs | 50 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 libimagentryfilter/src/builtin/header/version/range.rs diff --git a/libimagentryfilter/src/builtin/header/version/mod.rs b/libimagentryfilter/src/builtin/header/version/mod.rs index 5120056d..a2e86826 100644 --- a/libimagentryfilter/src/builtin/header/version/mod.rs +++ b/libimagentryfilter/src/builtin/header/version/mod.rs @@ -1,3 +1,4 @@ pub mod eq; -pub mod lt; pub mod gt; +pub mod lt; +pub mod range; diff --git a/libimagentryfilter/src/builtin/header/version/range.rs b/libimagentryfilter/src/builtin/header/version/range.rs new file mode 100644 index 00000000..9dffe5d6 --- /dev/null +++ b/libimagentryfilter/src/builtin/header/version/range.rs @@ -0,0 +1,50 @@ +use semver::Version; + +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; + +pub struct VersionInRange { + and: And, +} + +impl VersionInRange { + + pub fn new(lowerbound: Version, upperbound: Version) -> VersionInRange { + VersionInRange { and: VersionGt::new(lowerbound).and(Box::new(VersionLt::new(upperbound))) } + } + +} + +impl Filter for VersionInRange { + + fn filter(&self, e: &Entry) -> bool { + self.and.filter(e) + } + +} + +pub struct VersionOutOfRange { + not: Not +} + +impl VersionOutOfRange { + + pub fn new(lowerbound: Version, upperbound: Version) -> VersionOutOfRange { + VersionOutOfRange { not: VersionInRange::new(lowerbound, upperbound).not() } + } + +} + +impl Filter for VersionOutOfRange { + + fn filter(&self, e: &Entry) -> bool { + self.not.filter(e) + } + +} +