-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f9f609
commit 9d9c3f2
Showing
19 changed files
with
848 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use crate::common::geodata::geodata_proto; | ||
|
||
pub trait AttrMatcher { | ||
fn matches(&self, domain: &geodata_proto::Domain) -> bool; | ||
} | ||
|
||
pub struct BooleanAttrMatcher(pub String); | ||
|
||
impl AttrMatcher for BooleanAttrMatcher { | ||
fn matches(&self, domain: &geodata_proto::Domain) -> bool { | ||
for attr in &domain.attribute { | ||
if attr.key.eq_ignore_ascii_case(&self.0) { | ||
return true; | ||
} | ||
} | ||
false | ||
} | ||
} | ||
|
||
impl From<String> for BooleanAttrMatcher { | ||
fn from(s: String) -> Self { | ||
BooleanAttrMatcher(s) | ||
} | ||
} | ||
|
||
// logical AND of multiple attribute matchers | ||
pub struct AndAttrMatcher { | ||
list: Vec<Box<dyn AttrMatcher>>, | ||
} | ||
|
||
impl From<Vec<String>> for AndAttrMatcher { | ||
fn from(list: Vec<String>) -> Self { | ||
AndAttrMatcher { | ||
list: list | ||
.into_iter() | ||
.map(|s| Box::new(BooleanAttrMatcher(s)) as Box<dyn AttrMatcher>) | ||
.collect(), | ||
} | ||
} | ||
} | ||
|
||
impl AttrMatcher for AndAttrMatcher { | ||
fn matches(&self, domain: &geodata_proto::Domain) -> bool { | ||
for matcher in &self.list { | ||
if !matcher.matches(domain) { | ||
return false; | ||
} | ||
} | ||
true | ||
} | ||
} |
Oops, something went wrong.