pub struct Filter {
pub combine: Match,
pub rules: Vec<FilterRule>,
}Expand description
Rules, all, any or none of which must hold: what a filter_editor
edits. An empty filter lets everything through, and a number rule
whose number isn’t filled in yet (NaN) is left out.
Fields§
§combine: MatchHow the rules combine.
rules: Vec<FilterRule>The rules.
Implementations§
Source§impl Filter
impl Filter
Sourcepub fn matches(&self, value: impl Fn(&str) -> FieldValue) -> bool
pub fn matches(&self, value: impl Fn(&str) -> FieldValue) -> bool
Whether a row passes: value(key) gives the row’s value for a
field. An empty filter passes everything.
use ferrokit::{FieldValue, Filter, FilterRule, FilterTest, Match};
let big = Filter { combine: Match::All, rules: vec![FilterRule::Field { field: "total".into(), test: FilterTest::Greater(100.0) }] };
assert!(big.matches(|_| FieldValue::Number(120.0)));Sourcepub fn to_sql(&self) -> String
pub fn to_sql(&self) -> String
The filter as a SQL condition (for a WHERE): field keys become
double-quoted column names and values quoted literals, so what the
user types can’t change the query. Text tests other than “is” ignore
ASCII case, as SQLite’s LIKE does. An empty filter is 1.
use ferrokit::{Filter, FilterRule, FilterTest, Match};
let f = Filter { combine: Match::Any, rules: vec![
FilterRule::Field { field: "city".into(), test: FilterTest::Is("Oslo".into()) },
FilterRule::Field { field: "total".into(), test: FilterTest::AtLeast(100.0) },
] };
assert_eq!(f.to_sql(), r#"("city" = 'Oslo' OR "total" >= 100)"#);Trait Implementations§
impl StructuralPartialEq for Filter
Auto Trait Implementations§
impl Forget for Filter
impl Freeze for Filter
impl Move for Filter
impl RefUnwindSafe for Filter
impl Send for Filter
impl Sync for Filter
impl Unpin for Filter
impl UnsafeUnpin for Filter
impl UnwindSafe for Filter
Blanket Implementations§
impl<T> AutoreleaseSafe for Twhere
T: ?Sized,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more