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

source

pub fn all() -> Self

Returns a condition that always matches.

source

pub fn never() -> Self

Returns a condition that never matches.

source

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);
source

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"][..]);
source

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*"][..]);
source

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);
source

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);
source

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);
source

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);
source

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);
source

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");
source

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");
source

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")
);
source

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")
);
source

pub fn supported(&self) -> bool

Checks if Relay supports this condition (in other words if the condition had any unknown configuration which was serialized as “Unsupported” (because the configuration is either faulty or was created for a newer relay that supports some other condition types)

source

pub fn matches<T>(&self, value: &T) -> bool
where T: Getter + ?Sized,

Returns true if the rule matches the given value instance.

Trait Implementations§

source§

impl BitAnd for RuleCondition

§

type Output = RuleCondition

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: Self) -> Self::Output

Performs the & operation. Read more
source§

impl BitOr for RuleCondition

§

type Output = RuleCondition

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
source§

impl Clone for RuleCondition

source§

fn clone(&self) -> RuleCondition

Returns a copy 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 RuleCondition

source§

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

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

impl<'de> Deserialize<'de> for RuleCondition

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 Not for RuleCondition

§

type Output = RuleCondition

The resulting type after applying the ! operator.
source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
source§

impl PartialEq for RuleCondition

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for RuleCondition

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
source§

impl StructuralPartialEq for RuleCondition

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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

§

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>,

§

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>,

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

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