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(
9 self,
10 match_labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
11 ) -> Self;
12}
13
14impl LabelSelectorExt for metav1::LabelSelector {
15 fn new() -> Self {
16 default()
17 }
18
19 fn all_objects() -> Self {
20 Self {
21 match_expressions: Some(vec![]),
22 match_labels: Some(BTreeMap::new()),
23 }
24 }
25
26 fn no_objects() -> Self {
27 Self {
28 match_expressions: None,
29 match_labels: None,
30 }
31 }
32
33 fn match_labels(
34 self,
35 match_labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
36 ) -> Self {
37 let match_labels = match_labels
38 .into_iter()
39 .map(|(key, value)| (key.to_string(), value.to_string()))
40 .collect();
41 Self {
42 match_labels: Some(match_labels),
43 ..default()
45 }
46 }
47}