Skip to main content

FilterNode

Struct FilterNode 

Source
pub struct FilterNode {
    pub op: Option<String>,
    pub key: Option<String>,
    pub cmp: Option<String>,
    pub val: Option<String>,
    pub vals: Vec<String>,
    pub nodes: Vec<FilterNode>,
    /* private fields */
}
Expand description

A filter node that can be a leaf (comparison) or a branch (logical operation).

This structure is designed to be serialized/deserialized from JSON and can be constructed programmatically using the builder pattern.

Design goals:

  • Zero allocations during evaluation
  • Easy serialization to/from JSON
  • Programmatic construction via builder
  • Tree structure for complex filters

Performance optimizations:

  • HashSet cache for IN/NIN operators with many values (O(1) lookup)
  • Arc-wrapped HashSet shared across clones (zero-copy for socket subscriptions)

Fields§

§op: Option<String>

Logical operator for branch nodes: “and”, “or”, “not” If None or empty, this is a leaf node (comparison)

§key: Option<String>

Key for comparison (leaf nodes only)

§cmp: Option<String>

Comparison operator for leaf nodes “eq”, “neq”, “in”, “nin”, “ex”, “nex”, “sw”, “ew”, “ct”, “gt”, “gte”, “lt”, “lte”

§val: Option<String>

Single value for most comparisons

§vals: Vec<String>

Multiple values for set operations (in, nin)

§nodes: Vec<FilterNode>

Child nodes for logical operations

Implementations§

Source§

impl FilterNode

Source

pub fn new_comparison(key: String, cmp: CompareOp, val: String) -> Self

Creates a new leaf node with a comparison operation.

Source

pub fn new_set_comparison( key: String, cmp: CompareOp, vals: Vec<String>, ) -> Self

Creates a new leaf node with a set comparison operation (in/nin).

Source

pub fn new_existence(key: String, cmp: CompareOp) -> Self

Creates a new leaf node with an existence check.

Source

pub fn new_logical(op: LogicalOp, nodes: Vec<FilterNode>) -> Self

Creates a new branch node with a logical operation.

Source

pub fn is_sorted(&self) -> bool

Returns true if the vals vector is sorted and ready for binary search.

Source

pub fn optimize(&mut self)

Optimizes the filter node by sorting vectors for binary search. This avoids the overhead of building HashSets (allocations) while still providing O(log n) lookup performance.

Source

pub fn logical_op(&self) -> Option<LogicalOp>

Returns the logical operator if this is a branch node.

Source

pub fn compare_op(&self) -> CompareOp

Returns the comparison operator if this is a leaf node.

Source

pub fn key(&self) -> &str

Returns the key for leaf node comparisons.

Source

pub fn val(&self) -> &str

Returns the single value for leaf node comparisons.

Source

pub fn vals(&self) -> &[String]

Returns the multiple values for set comparisons.

Source

pub fn nodes(&self) -> &[FilterNode]

Returns the child nodes for logical operations.

Source

pub fn validate(&self) -> Option<String>

Validates the filter node structure.

Returns an error message if the node is invalid, None otherwise.

Trait Implementations§

Source§

impl Clone for FilterNode

Source§

fn clone(&self) -> FilterNode

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for FilterNode

Source§

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

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

impl<'de> Deserialize<'de> for FilterNode

Source§

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

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

impl PartialEq for FilterNode

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 FilterNode

Source§

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

Serialize this value into the given Serde serializer. Read more

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,