Enum relay_protocol::condition::RuleCondition
source · pub enum RuleCondition {
Eq(EqCondition),
Gte(GteCondition),
Lte(LteCondition),
Gt(GtCondition),
Lt(LtCondition),
Glob(GlobCondition),
Or(OrCondition),
And(AndCondition),
Not(NotCondition),
Any(AnyCondition),
All(AllCondition),
Unsupported,
}
Expand description
A condition that can be evaluated on structured data.
The basic conditions are eq
, glob
, and the comparison operators.
These conditions compare a data field specified through a path with a value or a set of values.
If the field’s value matches the values declared in the rule, the condition
returns true
.
Conditions can be combined with the logical operators and
, or
, and
not
(negate).
§Data Access
Rule conditions access data fields through the Getter
trait. Note that getters always have a
root namespace which must be part of the field’s path. If path’s root component does not match
the one of the passed getter instance, the rule condition will not be able to retrieve data and
likely not match.
§Serialization
Conditions are represented as nested JSON objects. The condition type is declared in the op
field.
§Example
use relay_protocol::RuleCondition;
let condition = !RuleCondition::eq("obj.status", "invalid");
Variants§
Eq(EqCondition)
A condition that compares values for equality.
This operator supports:
- boolean
- strings, optionally ignoring ASCII-case
- UUIDs
§Example
use relay_protocol::RuleCondition;
let condition = RuleCondition::eq("obj.status", "invalid");
Gte(GteCondition)
A condition that applies >=
.
§Example
use relay_protocol::RuleCondition;
let condition = RuleCondition::gte("obj.length", 10);
Lte(LteCondition)
A condition that applies <=
.
§Example
use relay_protocol::RuleCondition;
let condition = RuleCondition::lte("obj.length", 10);
Gt(GtCondition)
A condition that applies >
.
§Example
use relay_protocol::RuleCondition;
let condition = RuleCondition::gt("obj.length", 10);
Lt(LtCondition)
A condition that applies <
.
§Example
use relay_protocol::RuleCondition;
let condition = RuleCondition::lt("obj.length", 10);
Glob(GlobCondition)
A condition that uses glob matching.
§Example
use relay_protocol::RuleCondition;
let condition = RuleCondition::glob("obj.name", "error: *");
Or(OrCondition)
Combines multiple conditions using logical OR.
§Example
use relay_protocol::RuleCondition;
let condition = RuleCondition::eq("obj.status", "invalid")
| RuleCondition::eq("obj.status", "unknown");
And(AndCondition)
Combines multiple conditions using logical AND.
§Example
use relay_protocol::RuleCondition;
let condition = RuleCondition::eq("obj.status", "invalid")
& RuleCondition::gte("obj.length", 10);
Not(NotCondition)
Applies logical NOT to a condition.
§Example
use relay_protocol::RuleCondition;
let condition = !RuleCondition::eq("obj.status", "invalid");
Any(AnyCondition)
Loops over an array field and returns true if at least one element matches the inner condition.
§Example
use relay_protocol::RuleCondition;
let condition = RuleCondition::for_any("obj.exceptions",
RuleCondition::eq("name", "NullPointerException")
);
All(AllCondition)
Loops over an array field and returns true if all elements match the inner condition.
§Example
use relay_protocol::RuleCondition;
let condition = RuleCondition::for_all("obj.exceptions",
RuleCondition::eq("name", "NullPointerException")
);
Unsupported
An unsupported condition for future compatibility.
Implementations§
source§impl RuleCondition
impl RuleCondition
sourcepub fn eq(field: impl Into<String>, value: impl Into<Value>) -> Self
pub fn eq(field: impl Into<String>, value: impl Into<Value>) -> Self
Creates a condition that compares values for equality.
This operator supports:
- boolean
- strings
- UUIDs
§Examples
use relay_protocol::RuleCondition;
// Matches if the value is identical to the given string:
let condition = RuleCondition::eq("obj.status", "invalid");
// Matches if the value is identical to any of the given strings:
let condition = RuleCondition::eq("obj.status", &["invalid", "unknown"][..]);
// Matches a boolean flag:
let condition = RuleCondition::eq("obj.valid", false);
sourcepub fn eq_ignore_case(field: impl Into<String>, value: impl Into<Value>) -> Self
pub fn eq_ignore_case(field: impl Into<String>, value: impl Into<Value>) -> Self
Creates a condition that compares values for equality ignoring ASCII-case.
§Examples
use relay_protocol::RuleCondition;
// Matches if the value is identical to the given string:
let condition = RuleCondition::eq_ignore_case("obj.status", "invalid");
// Matches if the value is identical to any of the given strings:
let condition = RuleCondition::eq_ignore_case("obj.status", &["invalid", "unknown"][..]);
sourcepub fn glob(field: impl Into<String>, value: impl IntoStrings) -> Self
pub fn glob(field: impl Into<String>, value: impl IntoStrings) -> Self
Creates a condition that matches one or more glob patterns.
§Example
use relay_protocol::RuleCondition;
// Match a single pattern:
let condition = RuleCondition::glob("obj.name", "error: *");
// Match any of a list of patterns:
let condition = RuleCondition::glob("obj.name", &["error: *", "*failure*"][..]);
sourcepub fn gt(field: impl Into<String>, value: impl Into<Value>) -> Self
pub fn gt(field: impl Into<String>, value: impl Into<Value>) -> Self
Creates a condition that applies >
.
§Example
use relay_protocol::RuleCondition;
let condition = RuleCondition::gt("obj.length", 10);
sourcepub fn gte(field: impl Into<String>, value: impl Into<Value>) -> Self
pub fn gte(field: impl Into<String>, value: impl Into<Value>) -> Self
Creates a condition that applies >=
.
§Example
use relay_protocol::RuleCondition;
let condition = RuleCondition::gte("obj.length", 10);
sourcepub fn lt(field: impl Into<String>, value: impl Into<Value>) -> Self
pub fn lt(field: impl Into<String>, value: impl Into<Value>) -> Self
Creates a condition that applies <
.
§Example
use relay_protocol::RuleCondition;
let condition = RuleCondition::lt("obj.length", 10);
sourcepub fn lte(field: impl Into<String>, value: impl Into<Value>) -> Self
pub fn lte(field: impl Into<String>, value: impl Into<Value>) -> Self
Creates a condition that applies <=
.
§Example
use relay_protocol::RuleCondition;
let condition = RuleCondition::lte("obj.length", 10);
sourcepub fn and(self, other: RuleCondition) -> Self
pub fn and(self, other: RuleCondition) -> Self
Combines this condition and another condition with a logical AND operator.
The short-hand operator for this combinator is &
.
§Example
use relay_protocol::RuleCondition;
let condition = RuleCondition::eq("obj.status", "invalid")
& RuleCondition::gte("obj.length", 10);
sourcepub fn or(self, other: RuleCondition) -> Self
pub fn or(self, other: RuleCondition) -> Self
Combines this condition and another condition with a logical OR operator.
The short-hand operator for this combinator is |
.
§Example
use relay_protocol::RuleCondition;
let condition = RuleCondition::eq("obj.status", "invalid")
| RuleCondition::eq("obj.status", "unknown");
sourcepub fn negate(self) -> Self
pub fn negate(self) -> Self
Negates this condition with logical NOT.
The short-hand operator for this combinator is !
.
§Example
use relay_protocol::RuleCondition;
let condition = !RuleCondition::eq("obj.status", "invalid");
sourcepub fn for_any(field: impl Into<String>, inner: RuleCondition) -> Self
pub fn for_any(field: impl Into<String>, inner: RuleCondition) -> Self
Creates an AnyCondition
.
§Example
use relay_protocol::RuleCondition;
let condition = RuleCondition::for_any("obj.exceptions",
RuleCondition::eq("name", "NullPointerException")
);
sourcepub fn for_all(field: impl Into<String>, inner: RuleCondition) -> Self
pub fn for_all(field: impl Into<String>, inner: RuleCondition) -> Self
Creates an AllCondition
.
§Example
use relay_protocol::RuleCondition;
let condition = RuleCondition::for_all("obj.exceptions",
RuleCondition::eq("name", "NullPointerException")
);
Trait Implementations§
source§impl BitAnd for RuleCondition
impl BitAnd for RuleCondition
source§impl BitOr for RuleCondition
impl BitOr for RuleCondition
source§impl Clone for RuleCondition
impl Clone for RuleCondition
source§fn clone(&self) -> RuleCondition
fn clone(&self) -> RuleCondition
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for RuleCondition
impl Debug for RuleCondition
source§impl<'de> Deserialize<'de> for RuleCondition
impl<'de> Deserialize<'de> for RuleCondition
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>,
source§impl Not for RuleCondition
impl Not for RuleCondition
source§impl PartialEq for RuleCondition
impl PartialEq for RuleCondition
source§fn eq(&self, other: &RuleCondition) -> bool
fn eq(&self, other: &RuleCondition) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl Serialize for RuleCondition
impl Serialize for RuleCondition
impl StructuralPartialEq for RuleCondition
Auto Trait Implementations§
impl !Freeze for RuleCondition
impl RefUnwindSafe for RuleCondition
impl Send for RuleCondition
impl Sync for RuleCondition
impl Unpin for RuleCondition
impl UnwindSafe for RuleCondition
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,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)