upcloud_sdk/types/
common.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Default, Serialize, Deserialize)]
4pub struct Labels {
5 pub label: Vec<Label>,
6}
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct Label {
10 pub key: String,
11 pub value: String,
12}
13
14impl Labels {
15 pub fn new() -> Self {
16 Default::default()
17 }
18
19 pub fn with(mut self, key: &str, value: &str) -> Self {
20 self.label.push(Label { key: key.to_string(), value: value.to_string() });
21 self
22 }
23}
24
25#[derive(Debug, Default, Clone, Serialize, Deserialize)]
26pub struct Tags {
27 pub tag: Vec<String>,
28}
29
30#[derive(Debug, Default)]
32pub struct LabelFilter {
33 labels: Vec<String>,
34}
35
36impl LabelFilter {
37 pub fn new() -> Self {
38 Self { labels: Vec::new() }
39 }
40
41 pub fn with(mut self, key: &str, value: &str) -> Self {
42 self.labels.push(format!("{}={}", key, value));
43 self
44 }
45
46 pub fn add_label(&mut self, key: &str) -> &mut Self {
47 self.labels.push(key.to_string());
48 self
49 }
50
51 pub fn add_label_value(&mut self, key: &str, value: &str) -> &mut Self {
52 self.labels.push(format!("{}={}", key, value));
53 self
54 }
55
56 pub fn to_query_params(&self) -> String {
57 if self.labels.is_empty() {
58 String::new()
59 } else {
60 self.labels
61 .iter()
62 .map(|l| format!("label={}", urlencoding::encode(l)))
63 .collect::<Vec<_>>()
64 .join("&")
65 }
66 }
67}