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§
fn matches_object(&self, obj: Option<&K>) -> bool
Provided Methods§
Sourcefn not(self) -> Not<Self>where
Self: Sized,
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));
Sourcefn and<Other: Condition<K>>(self, other: Other) -> And<Self, Other>where
Self: Sized,
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));
Sourcefn or<Other: Condition<K>>(self, other: Other) -> Or<Self, Other>where
Self: Sized,
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));