pub trait Filter {
fn apply(&mut self, key: &str, value: u64) -> bool;
}
pub struct All;
impl Filter for All {
fn apply(&mut self, _: &str, _: u64) -> bool { true }
}
pub struct Select<F: FnMut(&str, u64) -> bool>(pub F);
impl<F: FnMut(&str, u64) -> bool> Filter for Select<F> {
fn apply(&mut self, key: &str, val: u64) -> bool {
self.0(key, val)
}
}
impl Filter for &str {
fn apply(&mut self, key: &str, _: u64) -> bool {
key.contains(&*self)
}
}
pub struct Contains<'l>(pub &'l str);
impl<'l> Filter for Contains<'l> {
fn apply(&mut self, key: &str, _: u64) -> bool {
key.contains(self.0)
}
}
pub struct StartsWith<'l>(pub &'l str);
impl<'l> Filter for StartsWith<'l> {
fn apply(&mut self, key: &str, _: u64) -> bool {
key.starts_with(self.0)
}
}
pub struct EndsWith<'l>(pub &'l str);
impl<'l> Filter for EndsWith<'l> {
fn apply(&mut self, key: &str, _: u64) -> bool {
key.ends_with(self.0)
}
}
pub struct GreaterThan(pub u64);
impl Filter for GreaterThan {
fn apply(&mut self, _key: &str, val: u64) -> bool {
val > self.0
}
}
pub struct LessThan(pub u64);
impl Filter for LessThan {
fn apply(&mut self, _key: &str, val: u64) -> bool {
val < self.0
}
}