Skip to main content

MetadataFilter

Enum MetadataFilter 

Source
pub enum MetadataFilter {
    Condition(Condition),
    And(Vec<MetadataFilter>),
    Or(Vec<MetadataFilter>),
    Not(Box<MetadataFilter>),
}
Expand description

A composable filter expression over Metadata.

Filters can be built from primitive Conditions and combined with MetadataFilter::and, MetadataFilter::or, and MetadataFilter::not.

§Examples

use qubit_metadata::{Metadata, MetadataFilter};

let mut meta = Metadata::new();
meta.set("env", "prod");
meta.set("version", 2_i64);

let f = MetadataFilter::equal("env", "prod")
    .and(MetadataFilter::greater_equal("version", 1_i64));

assert!(f.matches(&meta));

Variants§

§

Condition(Condition)

A leaf condition.

§

And(Vec<MetadataFilter>)

All child filters must match.

§

Or(Vec<MetadataFilter>)

At least one child filter must match.

§

Not(Box<MetadataFilter>)

The child filter must not match.

Implementations§

Source§

impl MetadataFilter

Source

pub fn equal<T: Serialize>(key: impl Into<String>, value: T) -> Self

Creates an equality filter: key == value.

Source

pub fn not_equal<T: Serialize>(key: impl Into<String>, value: T) -> Self

Creates a not-equal filter: key != value.

Source

pub fn greater<T: Serialize>(key: impl Into<String>, value: T) -> Self

Creates a greater-than filter: key > value.

Source

pub fn greater_equal<T: Serialize>(key: impl Into<String>, value: T) -> Self

Creates a greater-than-or-equal filter: key >= value.

Source

pub fn less<T: Serialize>(key: impl Into<String>, value: T) -> Self

Creates a less-than filter: key < value.

Source

pub fn less_equal<T: Serialize>(key: impl Into<String>, value: T) -> Self

Creates a less-than-or-equal filter: key <= value.

Source

pub fn exists(key: impl Into<String>) -> Self

Creates an existence filter: the key must be present.

Source

pub fn not_exists(key: impl Into<String>) -> Self

Creates a non-existence filter: the key must be absent.

Source

pub fn in_values<T, I>(key: impl Into<String>, values: I) -> Self
where T: Serialize, I: IntoIterator<Item = T>,

Creates an in-set filter: key ∈ values.

Source

pub fn not_in_values<T, I>(key: impl Into<String>, values: I) -> Self
where T: Serialize, I: IntoIterator<Item = T>,

Creates a not-in-set filter: key ∉ values.

Source

pub fn and(self, other: MetadataFilter) -> Self

Combines self and other with a logical AND.

If self is already an And node the new filter is appended to its children rather than creating a new nested node.

Source

pub fn or(self, other: MetadataFilter) -> Self

Combines self and other with a logical OR.

If self is already an Or node the new filter is appended to its children rather than creating a new nested node.

Source

pub fn not(self) -> Self

Wraps self in a logical NOT.

Source

pub fn matches(&self, meta: &Metadata) -> bool

Returns true if meta satisfies this filter.

Trait Implementations§

Source§

impl Clone for MetadataFilter

Source§

fn clone(&self) -> MetadataFilter

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 MetadataFilter

Source§

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

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

impl<'de> Deserialize<'de> for MetadataFilter

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 MetadataFilter

Source§

type Output = MetadataFilter

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl PartialEq for MetadataFilter

Source§

fn eq(&self, other: &MetadataFilter) -> 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 MetadataFilter

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 MetadataFilter

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