Trait kube_runtime::wait::Condition

source ·
pub trait Condition<K> {
    // Required method
    fn matches_object(&self, obj: Option<&K>) -> bool;

    // Provided methods
    fn not(self) -> Not<Self>
       where Self: Sized { ... }
    fn and<Other: Condition<K>>(self, other: Other) -> And<Self, Other>
       where Self: Sized { ... }
    fn or<Other: Condition<K>>(self, other: Other) -> Or<Self, Other>
       where Self: Sized { ... }
}
Expand description

A trait for condition functions to be used by await_condition

Note that this is auto-implemented for functions of type fn(Option<&K>) -> bool.

§Usage

use kube::runtime::wait::Condition;
use k8s_openapi::api::core::v1::Pod;
fn my_custom_condition(my_cond: &str) -> impl Condition<Pod> + '_ {
    move |obj: Option<&Pod>| {
        if let Some(pod) = &obj {
            if let Some(status) = &pod.status {
                if let Some(conds) = &status.conditions {
                    if let Some(pcond) = conds.iter().find(|c| c.type_ == my_cond) {
                        return pcond.status == "True";
                    }
                }
            }
        }
        false
    }
}

Required Methods§

source

fn matches_object(&self, obj: Option<&K>) -> bool

Provided Methods§

source

fn not(self) -> Not<Self>
where Self: Sized,

Returns a Condition that holds if self does not

§Usage
let condition: fn(Option<&()>) -> bool = |_| true;
assert!(condition.matches_object(None));
assert!(!condition.not().matches_object(None));
source

fn and<Other: Condition<K>>(self, other: Other) -> And<Self, Other>
where Self: Sized,

Returns a Condition that holds if self and other both do

§Usage
let cond_false: fn(Option<&()>) -> bool = |_| false;
let cond_true: fn(Option<&()>) -> bool = |_| true;
assert!(!cond_false.and(cond_false).matches_object(None));
assert!(!cond_false.and(cond_true).matches_object(None));
assert!(!cond_true.and(cond_false).matches_object(None));
assert!(cond_true.and(cond_true).matches_object(None));
source

fn or<Other: Condition<K>>(self, other: Other) -> Or<Self, Other>
where Self: Sized,

Returns a Condition that holds if either self or other does

§Usage
let cond_false: fn(Option<&()>) -> bool = |_| false;
let cond_true: fn(Option<&()>) -> bool = |_| true;
assert!(!cond_false.or(cond_false).matches_object(None));
assert!(cond_false.or(cond_true).matches_object(None));
assert!(cond_true.or(cond_false).matches_object(None));
assert!(cond_true.or(cond_true).matches_object(None));

Implementors§

source§

impl<A, B, K> Condition<K> for And<A, B>
where A: Condition<K>, B: Condition<K>,

source§

impl<A, B, K> Condition<K> for Or<A, B>
where A: Condition<K>, B: Condition<K>,

source§

impl<A: Condition<K>, K> Condition<K> for Not<A>

source§

impl<K, F: Fn(Option<&K>) -> bool> Condition<K> for F