Skip to main content

Filter

Enum Filter 

Source
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 to false for a record with no author field. It only matches records that explicitly carry an author field whose value is not "ada".
  • Filter::not(Filter::eq("author", "ada")) evaluates to true for a record with no author. 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.

Fields

§field: String

The metadata field to test.

§value: Value

The value to compare against.

§

Neq

Matches when field does not equal value.

Fields

§field: String

The metadata field to test.

§value: Value

The value to compare against.

§

Lt

Matches when field is strictly less than value.

Fields

§field: String

The metadata field to test.

§value: Value

The value to compare against.

§

Lte

Matches when field is less than or equal to value.

Fields

§field: String

The metadata field to test.

§value: Value

The value to compare against.

§

Gt

Matches when field is strictly greater than value.

Fields

§field: String

The metadata field to test.

§value: Value

The value to compare against.

§

Gte

Matches when field is greater than or equal to value.

Fields

§field: String

The metadata field to test.

§value: Value

The value to compare against.

§

In

Matches when field equals any of values.

Fields

§field: String

The metadata field to test.

§values: Vec<Value>

The set of acceptable 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

Source

pub fn eq(field: impl Into<String>, value: Value) -> Filter

Builds an Eq leaf: field == value.

§Examples
use iqdb_types::{Filter, Value};

let f = Filter::eq("year", Value::Int(2026));
assert_eq!(f, Filter::Eq { field: "year".to_string(), value: Value::Int(2026) });
Source

pub fn neq(field: impl Into<String>, value: Value) -> Filter

Builds a Neq leaf: field != value.

§Examples
use iqdb_types::{Filter, Value};

let f = Filter::neq("status", Value::String("draft".to_string()));
assert!(matches!(f, Filter::Neq { .. }));
Source

pub fn lt(field: impl Into<String>, value: Value) -> Filter

Builds an Lt leaf: field < value.

§Examples
use iqdb_types::{Filter, Value};

let f = Filter::lt("year", Value::Int(2000));
assert!(matches!(f, Filter::Lt { .. }));
Source

pub fn lte(field: impl Into<String>, value: Value) -> Filter

Builds an Lte leaf: field <= value.

§Examples
use iqdb_types::{Filter, Value};

let f = Filter::lte("year", Value::Int(2000));
assert!(matches!(f, Filter::Lte { .. }));
Source

pub fn gt(field: impl Into<String>, value: Value) -> Filter

Builds a Gt leaf: field > value.

§Examples
use iqdb_types::{Filter, Value};

let f = Filter::gt("year", Value::Int(2000));
assert!(matches!(f, Filter::Gt { .. }));
Source

pub fn gte(field: impl Into<String>, value: Value) -> Filter

Builds a Gte leaf: field >= value.

§Examples
use iqdb_types::{Filter, Value};

let f = Filter::gte("year", Value::Int(2000));
assert!(matches!(f, Filter::Gte { .. }));
Source

pub fn is_in(field: impl Into<String>, values: Vec<Value>) -> Filter

Builds an In leaf: field equals any of values.

§Examples
use iqdb_types::{Filter, Value};

let f = Filter::is_in("year", vec![Value::Int(2025), Value::Int(2026)]);
assert!(matches!(f, Filter::In { .. }));
Source

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(_)));
Source

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(_)));
Source

pub fn not(inner: Filter) -> Filter

Builds a Not node: negates the sub-filter.

§Examples
use iqdb_types::{Filter, Value};

let f = Filter::not(Filter::eq("a", Value::Null));
assert!(matches!(f, Filter::Not(_)));

Trait Implementations§

Source§

impl Clone for Filter

Source§

fn clone(&self) -> Filter

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Filter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Filter

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Filter, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Filter

Source§

fn eq(&self, other: &Filter) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Filter

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Filter

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<E> WithErrorCode<E> for E

Source§

fn with_code(self, code: impl Into<String>) -> CodedError<E>

Attach an error code to an error
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more