datadog_api_client/datadogV2/model/
model_metrics_data_source.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 MetricsDataSource {
10    METRICS,
11    CLOUD_COST,
12    UnparsedObject(crate::datadog::UnparsedObject),
13}
14
15impl ToString for MetricsDataSource {
16    fn to_string(&self) -> String {
17        match self {
18            Self::METRICS => String::from("metrics"),
19            Self::CLOUD_COST => String::from("cloud_cost"),
20            Self::UnparsedObject(v) => v.value.to_string(),
21        }
22    }
23}
24
25impl Serialize for MetricsDataSource {
26    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
27    where
28        S: Serializer,
29    {
30        match self {
31            Self::UnparsedObject(v) => v.serialize(serializer),
32            _ => serializer.serialize_str(self.to_string().as_str()),
33        }
34    }
35}
36
37impl<'de> Deserialize<'de> for MetricsDataSource {
38    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
39    where
40        D: Deserializer<'de>,
41    {
42        let s: String = String::deserialize(deserializer)?;
43        Ok(match s.as_str() {
44            "metrics" => Self::METRICS,
45            "cloud_cost" => Self::CLOUD_COST,
46            _ => Self::UnparsedObject(crate::datadog::UnparsedObject {
47                value: serde_json::Value::String(s.into()),
48            }),
49        })
50    }
51}