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
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
use crate::structure::T;

pub enum LabelType {
    Str(String),
    Bool(bool),
    T(T),
}

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

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

impl From<String> for Labels {
    fn from(param: String) -> Labels {
        Labels(vec![LabelType::Str(param)])
    }
}

impl From<T> for Labels {
    fn from(param: T) -> Labels {
        Labels(vec![LabelType::T(param)])
    }
}

impl From<()> for Labels {
    fn from(_: ()) -> Labels {
        Labels(vec![])
    }
}
impl From<Vec<&str>> for Labels {
    fn from(param: Vec<&str>) -> Labels {
        Labels(
            param
                .into_iter()
                .map(|val| LabelType::Str(String::from(val)))
                .collect(),
        )
    }
}
impl From<Vec<String>> for Labels {
    fn from(param: Vec<String>) -> Labels {
        Labels(param.into_iter().map(LabelType::Str).collect())
    }
}

impl From<bool> for Labels {
    fn from(param: bool) -> Labels {
        Labels(vec![LabelType::Bool(param)])
    }
}

impl From<(bool, Vec<&str>)> for Labels {
    fn from(param: (bool, Vec<&str>)) -> Labels {
        let mut out: Vec<LabelType> = vec![LabelType::Bool(param.0)];
        out.append(&mut Into::<Labels>::into(param.1).0.drain(..).collect());
        Labels(out)
    }
}

impl From<(bool, T, Vec<&str>)> for Labels {
    fn from(param: (bool, T, Vec<&str>)) -> Labels {
        let mut out: Vec<LabelType> = vec![LabelType::Bool(param.0)];
        out.append(&mut Into::<Labels>::into(param.1).0.drain(..).collect());
        out.append(&mut Into::<Labels>::into(param.2).0.drain(..).collect());
        Labels(out)
    }
}

impl From<(T, Vec<&str>)> for Labels {
    fn from(param: (T, Vec<&str>)) -> Labels {
        let mut out: Vec<LabelType> = vec![LabelType::T(param.0)];
        out.append(&mut Into::<Labels>::into(param.1).0.drain(..).collect());
        Labels(out)
    }
}

macro_rules! impl_into_labels_str {
    ($n:expr) => {
        impl From<[&str; $n]> for Labels {
            fn from(param: [&str; $n]) -> Labels {
                Labels(
                    param
                        .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 From<[String; $n]> for Labels {
            fn from(param: [String; $n]) -> Labels {
                Labels(
                    param
                        .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);