pub struct Condition { /* private fields */ }Expand description
Public query types: a Condition groups into a Conjunction, conjunctions into a DnfQuery.
Represents a single field operator value test in a DNF query.
Conditions are the leaves of a query: a Conjunction is an AND of
conditions, and a DnfQuery is an OR of conjunctions.
§Examples
use dnf::{DnfQuery, Op};
let query = DnfQuery::builder()
.or(|c| c.and("age", Op::GT, 18))
.build();
let condition = &query.conjunctions()[0].conditions()[0];
assert_eq!(condition.field_name(), "age");
assert_eq!(condition.operator(), &Op::GT);Implementations§
Source§impl Condition
impl Condition
Sourcepub fn field_name(&self) -> &str
pub fn field_name(&self) -> &str
Returns the field name this condition tests.
Sourcepub fn evaluate<T: DnfEvaluable>(&self, target: &T) -> bool
pub fn evaluate<T: DnfEvaluable>(&self, target: &T) -> bool
Evaluates the condition against a single target.
Returns whatever DnfEvaluable::evaluate_field returns. Custom
operators are not dispatched here — call
DnfQuery::evaluate for that.
§Examples
use dnf::{Condition, DnfEvaluable, Op, Value};
#[derive(DnfEvaluable)]
struct User { age: u32 }
let user = User { age: 30 };
let cond = dnf::DnfQuery::builder()
.or(|c| c.and("age", Op::GT, 18))
.build()
.conjunctions()[0]
.conditions()[0]
.clone();
assert!(cond.evaluate(&user));Trait Implementations§
Source§impl<'de> Deserialize<'de> for Condition
impl<'de> Deserialize<'de> for Condition
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Condition
Auto Trait Implementations§
impl Freeze for Condition
impl RefUnwindSafe for Condition
impl Send for Condition
impl Sync for Condition
impl Unpin for Condition
impl UnsafeUnpin for Condition
impl UnwindSafe for Condition
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
Mutably borrows from an owned value. Read more