datadog_api_client/datadogV2/model/
model_ci_app_aggregation_function.rs1use serde::{Deserialize, Deserializer, Serialize, Serializer};
6
7#[non_exhaustive]
8#[derive(Clone, Debug, Eq, PartialEq)]
9pub enum CIAppAggregationFunction {
10 COUNT,
11 CARDINALITY,
12 PERCENTILE_75,
13 PERCENTILE_90,
14 PERCENTILE_95,
15 PERCENTILE_98,
16 PERCENTILE_99,
17 SUM,
18 MIN,
19 MAX,
20 AVG,
21 MEDIAN,
22 LATEST,
23 EARLIEST,
24 MOST_FREQUENT,
25 DELTA,
26 UnparsedObject(crate::datadog::UnparsedObject),
27}
28
29impl ToString for CIAppAggregationFunction {
30 fn to_string(&self) -> String {
31 match self {
32 Self::COUNT => String::from("count"),
33 Self::CARDINALITY => String::from("cardinality"),
34 Self::PERCENTILE_75 => String::from("pc75"),
35 Self::PERCENTILE_90 => String::from("pc90"),
36 Self::PERCENTILE_95 => String::from("pc95"),
37 Self::PERCENTILE_98 => String::from("pc98"),
38 Self::PERCENTILE_99 => String::from("pc99"),
39 Self::SUM => String::from("sum"),
40 Self::MIN => String::from("min"),
41 Self::MAX => String::from("max"),
42 Self::AVG => String::from("avg"),
43 Self::MEDIAN => String::from("median"),
44 Self::LATEST => String::from("latest"),
45 Self::EARLIEST => String::from("earliest"),
46 Self::MOST_FREQUENT => String::from("most_frequent"),
47 Self::DELTA => String::from("delta"),
48 Self::UnparsedObject(v) => v.value.to_string(),
49 }
50 }
51}
52
53impl Serialize for CIAppAggregationFunction {
54 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
55 where
56 S: Serializer,
57 {
58 match self {
59 Self::UnparsedObject(v) => v.serialize(serializer),
60 _ => serializer.serialize_str(self.to_string().as_str()),
61 }
62 }
63}
64
65impl<'de> Deserialize<'de> for CIAppAggregationFunction {
66 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
67 where
68 D: Deserializer<'de>,
69 {
70 let s: String = String::deserialize(deserializer)?;
71 Ok(match s.as_str() {
72 "count" => Self::COUNT,
73 "cardinality" => Self::CARDINALITY,
74 "pc75" => Self::PERCENTILE_75,
75 "pc90" => Self::PERCENTILE_90,
76 "pc95" => Self::PERCENTILE_95,
77 "pc98" => Self::PERCENTILE_98,
78 "pc99" => Self::PERCENTILE_99,
79 "sum" => Self::SUM,
80 "min" => Self::MIN,
81 "max" => Self::MAX,
82 "avg" => Self::AVG,
83 "median" => Self::MEDIAN,
84 "latest" => Self::LATEST,
85 "earliest" => Self::EARLIEST,
86 "most_frequent" => Self::MOST_FREQUENT,
87 "delta" => Self::DELTA,
88 _ => Self::UnparsedObject(crate::datadog::UnparsedObject {
89 value: serde_json::Value::String(s.into()),
90 }),
91 })
92 }
93}