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
use crate::{
evt::Event,
gauge::{Gauge, RawGauge},
label::Label,
};
pub struct Multi {
query: String,
label: Vec<Label>,
gauge: Vec<Gauge>,
}
impl Multi {
pub fn as_query(&self) -> &str {
self.query.as_str()
}
pub fn as_label(&self) -> &[Label] {
&self.label
}
pub fn as_gauge(&self) -> &[Gauge] {
&self.gauge
}
}
impl TryFrom<RawMulti> for Multi {
type Error = Event;
fn try_from(r: RawMulti) -> Result<Self, Self::Error> {
let query: String = r.query;
let label: Vec<_> = r.label;
let gauge: Vec<Gauge> = r.gauge.into_iter().try_fold(vec![], |mut v, r| {
let g: Gauge = Gauge::try_from(r)?;
v.push(g);
Ok(v)
})?;
Ok(Self {
query,
label,
gauge,
})
}
}
#[derive(serde::Deserialize)]
pub struct RawMulti {
query: String,
label: Vec<Label>,
gauge: Vec<RawGauge>,
}