datadog_api_client/datadogV2/model/
model_rum_aggregation_function.rs

1// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2// This product includes software developed at Datadog (https://www.datadoghq.com/).
3// Copyright 2019-Present Datadog, Inc.
4
5use serde::{Deserialize, Deserializer, Serialize, Serializer};
6
7#[non_exhaustive]
8#[derive(Clone, Debug, Eq, PartialEq)]
9pub enum RUMAggregationFunction {
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    UnparsedObject(crate::datadog::UnparsedObject),
23}
24
25impl ToString for RUMAggregationFunction {
26    fn to_string(&self) -> String {
27        match self {
28            Self::COUNT => String::from("count"),
29            Self::CARDINALITY => String::from("cardinality"),
30            Self::PERCENTILE_75 => String::from("pc75"),
31            Self::PERCENTILE_90 => String::from("pc90"),
32            Self::PERCENTILE_95 => String::from("pc95"),
33            Self::PERCENTILE_98 => String::from("pc98"),
34            Self::PERCENTILE_99 => String::from("pc99"),
35            Self::SUM => String::from("sum"),
36            Self::MIN => String::from("min"),
37            Self::MAX => String::from("max"),
38            Self::AVG => String::from("avg"),
39            Self::MEDIAN => String::from("median"),
40            Self::UnparsedObject(v) => v.value.to_string(),
41        }
42    }
43}
44
45impl Serialize for RUMAggregationFunction {
46    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
47    where
48        S: Serializer,
49    {
50        match self {
51            Self::UnparsedObject(v) => v.serialize(serializer),
52            _ => serializer.serialize_str(self.to_string().as_str()),
53        }
54    }
55}
56
57impl<'de> Deserialize<'de> for RUMAggregationFunction {
58    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
59    where
60        D: Deserializer<'de>,
61    {
62        let s: String = String::deserialize(deserializer)?;
63        Ok(match s.as_str() {
64            "count" => Self::COUNT,
65            "cardinality" => Self::CARDINALITY,
66            "pc75" => Self::PERCENTILE_75,
67            "pc90" => Self::PERCENTILE_90,
68            "pc95" => Self::PERCENTILE_95,
69            "pc98" => Self::PERCENTILE_98,
70            "pc99" => Self::PERCENTILE_99,
71            "sum" => Self::SUM,
72            "min" => Self::MIN,
73            "max" => Self::MAX,
74            "avg" => Self::AVG,
75            "median" => Self::MEDIAN,
76            _ => Self::UnparsedObject(crate::datadog::UnparsedObject {
77                value: serde_json::Value::String(s.into()),
78            }),
79        })
80    }
81}