pub trait DnfEvaluable {
// Required methods
fn evaluate_field(
&self,
field_name: &str,
operator: &Op,
value: &Value,
) -> bool;
fn fields() -> impl Iterator<Item = FieldInfo>;
// Provided methods
fn field_value(&self, field_name: &str) -> Option<Value> { ... }
fn validate_field_path(path: &str) -> Option<FieldKind> { ... }
}Expand description
Types that can be evaluated against a DnfQuery.
Normally derived with #[derive(DnfEvaluable)]. Implement manually for
computed fields, custom value types, or types that the derive macro does not
support (enums, types with non-DnfField fields, etc.).
§Examples
use dnf::{DnfEvaluable, DnfQuery, Op};
#[derive(DnfEvaluable)]
struct User { age: u32, name: String }
let user = User { age: 25, name: "Alice".into() };
let query = DnfQuery::builder()
.or(|c| c.and("age", Op::GTE, 18))
.build();
assert!(query.evaluate(&user));Required Methods§
Sourcefn evaluate_field(&self, field_name: &str, operator: &Op, value: &Value) -> bool
fn evaluate_field(&self, field_name: &str, operator: &Op, value: &Value) -> bool
Evaluates one condition against self.
Returns true if field_name exists and the comparison succeeds.
Returns false for unknown fields or type mismatches — no error is
raised, since a query that cannot match silently fails the row.
§Examples
use dnf::{DnfEvaluable, Op, Value};
#[derive(DnfEvaluable)]
struct User { age: u32 }
let user = User { age: 30 };
assert!(user.evaluate_field("age", &Op::GT, &Value::Uint(18)));
assert!(!user.evaluate_field("missing", &Op::EQ, &Value::Uint(0)));Sourcefn fields() -> impl Iterator<Item = FieldInfo>
fn fields() -> impl Iterator<Item = FieldInfo>
Returns metadata for every queryable field on the type.
Fields marked #[dnf(skip)] are excluded. The iterator does not
allocate — collect into a Vec if you need a snapshot.
§Examples
use dnf::DnfEvaluable;
#[derive(DnfEvaluable)]
struct User { age: u32, name: String }
let names: Vec<_> = User::fields().map(|f| f.name()).collect();
assert_eq!(names, vec!["age", "name"]);Provided Methods§
Sourcefn field_value(&self, field_name: &str) -> Option<Value>
fn field_value(&self, field_name: &str) -> Option<Value>
Returns the field’s value as a Value for custom-operator evaluation.
Standard operators use evaluate_field directly
without converting to Value; this method is only called for
custom operators registered through OpRegistry.
Returns None if the field does not exist. The default implementation
always returns None; the derive macro overrides it.
§Examples
use dnf::{DnfEvaluable, Value};
#[derive(DnfEvaluable)]
struct User { age: u32 }
let user = User { age: 30 };
assert_eq!(user.field_value("age"), Some(Value::Uint(30)));
assert_eq!(user.field_value("missing"), None);Sourcefn validate_field_path(path: &str) -> Option<FieldKind>
fn validate_field_path(path: &str) -> Option<FieldKind>
Returns the FieldKind of the field at path, or None if the
path does not name a known field.
path may be a dotted nested path (e.g., address.city). The
default implementation only validates the root segment; the derive
macro overrides this to recurse into nested struct fields, so a
typo such as address.zity is detected when address is annotated
with #[dnf(nested)].
Iterator/map field boundaries (Vec<T>, HashMap<K, V>, …) are
treated as opaque: validation accepts the field’s kind and stops
recursing, since trailing segments use runtime-interpreted syntax
such as @values or ["key"].
§Examples
use dnf::{DnfEvaluable, FieldKind};
#[derive(DnfEvaluable)]
struct User { age: u32 }
assert_eq!(User::validate_field_path("age"), Some(FieldKind::Scalar));
assert_eq!(User::validate_field_path("missing"), None);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".