Skip to main content

libimagentryfilter/builtin/header/version/
range.rs

1//
2// imag - the personal information management suite for the commandline
3// Copyright (C) 2015-2020 Matthias Beyer <mail@beyermatthias.de> and contributors
4//
5// This library is free software; you can redistribute it and/or
6// modify it under the terms of the GNU Lesser General Public
7// License as published by the Free Software Foundation; version
8// 2.1 of the License.
9//
10// This library is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13// Lesser General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public
16// License along with this library; if not, write to the Free Software
17// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18//
19
20use semver::Version;
21
22use libimagstore::store::Entry;
23
24use crate::builtin::header::version::gt::VersionGt;
25use crate::builtin::header::version::lt::VersionLt;
26use filters::filter::Filter;
27use filters::ops::and::And;
28use filters::ops::not::Not;
29
30pub struct VersionInRange {
31    and: And<VersionGt, VersionLt>,
32}
33
34impl VersionInRange {
35
36    pub fn new(lowerbound: Version, upperbound: Version) -> VersionInRange {
37        VersionInRange { and: VersionGt::new(lowerbound).and(VersionLt::new(upperbound)) }
38    }
39
40}
41
42impl Filter<Entry> for VersionInRange {
43
44    fn filter(&self, e: &Entry) -> bool {
45        self.and.filter(e)
46    }
47
48}
49
50pub struct VersionOutOfRange {
51    not: Not<VersionInRange>
52}
53
54impl VersionOutOfRange {
55
56    pub fn new(lowerbound: Version, upperbound: Version) -> VersionOutOfRange {
57        VersionOutOfRange { not: VersionInRange::new(lowerbound, upperbound).not() }
58    }
59
60}
61
62impl Filter<Entry> for VersionOutOfRange {
63
64    fn filter(&self, e: &Entry) -> bool {
65        self.not.filter(e)
66    }
67
68}
69