1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
pub enum LabelType {
    Str(String),
    Bool(bool),
}

pub struct Labels(pub(crate) Vec<LabelType>);

impl Into<Labels> for &str {
    fn into(self) -> Labels {
        Labels(vec![LabelType::Str(String::from(self))])
    }
}

impl Into<Labels> for String {
    fn into(self) -> Labels {
        Labels(vec![LabelType::Str(self)])
    }
}

impl Into<Labels> for () {
    fn into(self) -> Labels {
        Labels(vec![])
    }
}

impl Into<Labels> for Vec<&str> {
    fn into(self) -> Labels {
        Labels(
            self.into_iter()
                .map(|val| LabelType::Str(String::from(val)))
                .collect(),
        )
    }
}

impl Into<Labels> for Vec<String> {
    fn into(self) -> Labels {
        Labels(self.into_iter().map(|val| LabelType::Str(val)).collect())
    }
}

impl Into<Labels> for bool {
    fn into(self) -> Labels {
        Labels(vec![LabelType::Bool(self)])
    }
}

macro_rules! impl_into_labels_str {
    ($n:expr) => {
        impl Into<Labels> for [&str; $n] {
            fn into(self) -> Labels {
                Labels(
                    self.iter()
                        .map(|s| LabelType::Str(String::from(*s)))
                        .collect(),
                )
            }
        }
    };
}

impl_into_labels_str!(1);
impl_into_labels_str!(2);
impl_into_labels_str!(3);
impl_into_labels_str!(4);
impl_into_labels_str!(5);
impl_into_labels_str!(6);
impl_into_labels_str!(7);
impl_into_labels_str!(8);
impl_into_labels_str!(9);
impl_into_labels_str!(10);

macro_rules! impl_into_labels_string {
    ($n:expr) => {
        impl Into<Labels> for [String; $n] {
            fn into(self) -> Labels {
                Labels(self.iter().map(|val| LabelType::Str(val.clone())).collect())
            }
        }
    };
}

impl_into_labels_string!(1);
impl_into_labels_string!(2);
impl_into_labels_string!(3);
impl_into_labels_string!(4);
impl_into_labels_string!(5);
impl_into_labels_string!(6);
impl_into_labels_string!(7);
impl_into_labels_string!(8);
impl_into_labels_string!(9);
impl_into_labels_string!(10);