k8s_openapi_ext/ext/
label_selector.rs1use super::*;
2
3pub trait LabelSelectorExt {
4 fn all_objects() -> Self;
5 fn no_objects() -> Self;
6 fn new() -> Self;
7
8 fn match_labels(match_labels: impl IntoIterator<Item = (impl ToString, impl ToString)>)
9 -> Self;
10}
11
12impl LabelSelectorExt for metav1::LabelSelector {
13 fn new() -> Self {
14 default()
15 }
16
17 fn all_objects() -> Self {
18 Self {
19 match_expressions: Some(vec![]),
20 match_labels: Some(BTreeMap::new()),
21 }
22 }
23
24 fn no_objects() -> Self {
25 Self {
26 match_expressions: None,
27 match_labels: None,
28 }
29 }
30
31 fn match_labels(
32 match_labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
33 ) -> Self {
34 let match_labels = match_labels
35 .into_iter()
36 .map(|(key, value)| (key.to_string(), value.to_string()))
37 .collect();
38 Self {
39 match_labels: Some(match_labels),
40 ..default()
42 }
43 }
44}