pub enum Filter {
Eq {
field: String,
value: Value,
},
Neq {
field: String,
value: Value,
},
Lt {
field: String,
value: Value,
},
Lte {
field: String,
value: Value,
},
Gt {
field: String,
value: Value,
},
Gte {
field: String,
value: Value,
},
In {
field: String,
values: Vec<Value>,
},
And(Vec<Filter>),
Or(Vec<Filter>),
Not(Box<Filter>),
}Expand description
A boolean filter expression over record metadata.
Leaves compare one field against a Value; And/Or/Not combine
sub-expressions. Build it with the constructor helpers rather than the
variants directly.
§Null and absent-field semantics
Filter follows a closed-world rule: a leaf comparison whose field is
absent from a record’s metadata evaluates to false. This applies to every
leaf — Eq, Neq, Lt,
Lte, Gt, Gte, and
In. Type mismatches between the field’s stored value and
the literal also evaluate to false (a Value::Int field compared against
a Value::String literal does not match).
This makes Neq and Not(Eq) not interchangeable on absent fields:
Filter::neq("author", "ada")evaluates tofalsefor a record with noauthorfield. It only matches records that explicitly carry anauthorfield whose value is not"ada".Filter::not(Filter::eq("author", "ada"))evaluates totruefor a record with noauthor. This is the idiom for “records without this field, or with a non-matching value.”
Value::Float(NaN) under Lt/Lte/Gt/Gte also evaluates to false
(IEEE-754 unordered).
An explicit IsNull / Exists leaf is intentionally not part of v0.1; the
Not(Eq(...)) idiom covers the common case. It is tracked as a possible
additive variant for a later release.
§Examples
use iqdb_types::{Filter, Value};
// author == "ada" AND NOT (year > 2000)
let filter = Filter::and(vec![
Filter::eq("author", Value::String("ada".to_string())),
Filter::not(Filter::gt("year", Value::Int(2000))),
]);
assert_eq!(
filter,
Filter::And(vec![
Filter::Eq { field: "author".to_string(), value: Value::String("ada".to_string()) },
Filter::Not(Box::new(Filter::Gt { field: "year".to_string(), value: Value::Int(2000) })),
]),
);Variants§
Eq
Matches when field equals value.
Neq
Matches when field does not equal value.
Lt
Matches when field is strictly less than value.
Lte
Matches when field is less than or equal to value.
Gt
Matches when field is strictly greater than value.
Gte
Matches when field is greater than or equal to value.
In
Matches when field equals any of values.
And(Vec<Filter>)
Matches when every sub-filter matches.
Or(Vec<Filter>)
Matches when any sub-filter matches.
Not(Box<Filter>)
Matches when the sub-filter does not match.
Implementations§
Source§impl Filter
impl Filter
Sourcepub fn and(filters: Vec<Filter>) -> Filter
pub fn and(filters: Vec<Filter>) -> Filter
Builds an And node: every sub-filter must match.
An empty filters vector evaluates to true (vacuous truth —
“every element of an empty set satisfies the predicate”). A caller
using Filter::and(vec![]) as a “match everything” filter is
relying on documented behaviour.
§Examples
use iqdb_types::{Filter, Value};
let f = Filter::and(vec![
Filter::eq("a", Value::Bool(true)),
Filter::eq("b", Value::Bool(false)),
]);
assert!(matches!(f, Filter::And(_)));Sourcepub fn or(filters: Vec<Filter>) -> Filter
pub fn or(filters: Vec<Filter>) -> Filter
Builds an Or node: any sub-filter may match.
An empty filters vector evaluates to false (“no element
of an empty set satisfies the predicate”). A caller using
Filter::or(vec![]) as a “match nothing” filter is relying on
documented behaviour.
§Examples
use iqdb_types::{Filter, Value};
let f = Filter::or(vec![
Filter::eq("a", Value::Bool(true)),
Filter::eq("b", Value::Bool(true)),
]);
assert!(matches!(f, Filter::Or(_)));Trait Implementations§
Source§impl<'de> Deserialize<'de> for Filter
impl<'de> Deserialize<'de> for Filter
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Filter, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Filter, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for Filter
impl Serialize for Filter
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for Filter
Auto Trait Implementations§
impl Freeze 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§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more