barter_integration/
metric.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, PartialOrd, PartialEq, Serialize)]
4pub struct Metric {
5    /// Metric name.
6    pub name: &'static str,
7
8    /// Milliseconds since the Unix epoch.
9    pub time: u64,
10
11    /// Key-Value pairs to categorise the Metric.
12    pub tags: Vec<Tag>,
13
14    /// Observed measurements.
15    pub fields: Vec<Field>,
16}
17
18#[derive(Debug, Clone, Serialize, Ord, PartialOrd, Eq, PartialEq)]
19pub struct Tag {
20    pub key: &'static str,
21    pub value: String,
22}
23
24#[derive(Debug, Clone, PartialOrd, PartialEq, Serialize)]
25pub struct Field {
26    pub key: &'static str,
27    pub value: Value,
28}
29
30#[derive(Debug, Clone, PartialOrd, PartialEq, Deserialize, Serialize)]
31pub enum Value {
32    Float(f64),
33    Int(i64),
34    UInt(u64),
35    Bool(bool),
36    String(String),
37}
38
39impl<S> From<(&'static str, S)> for Tag
40where
41    S: Into<String>,
42{
43    fn from((key, value): (&'static str, S)) -> Self {
44        Self::new(key, value)
45    }
46}
47
48impl Tag {
49    pub fn new<S>(key: &'static str, value: S) -> Self
50    where
51        S: Into<String>,
52    {
53        Self {
54            key,
55            value: value.into(),
56        }
57    }
58}
59
60impl<S> From<(&'static str, S)> for Field
61where
62    S: Into<Value>,
63{
64    fn from((key, value): (&'static str, S)) -> Self {
65        Self::new(key, value)
66    }
67}
68
69impl Field {
70    pub fn new<S>(key: &'static str, value: S) -> Self
71    where
72        S: Into<Value>,
73    {
74        Self {
75            key,
76            value: value.into(),
77        }
78    }
79}
80
81impl From<f64> for Value {
82    fn from(value: f64) -> Self {
83        Self::Float(value)
84    }
85}
86
87impl From<i64> for Value {
88    fn from(value: i64) -> Self {
89        Self::Int(value)
90    }
91}
92
93impl From<u64> for Value {
94    fn from(value: u64) -> Self {
95        Self::UInt(value)
96    }
97}
98
99impl From<bool> for Value {
100    fn from(value: bool) -> Self {
101        Self::Bool(value)
102    }
103}
104
105impl From<String> for Value {
106    fn from(value: String) -> Self {
107        Self::String(value)
108    }
109}