datadog_api_client/datadogV1/model/
model_topology_query_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 TopologyQueryDataSource {
10    DATA_STREAMS,
11    SERVICE_MAP,
12    UnparsedObject(crate::datadog::UnparsedObject),
13}
14
15impl ToString for TopologyQueryDataSource {
16    fn to_string(&self) -> String {
17        match self {
18            Self::DATA_STREAMS => String::from("data_streams"),
19            Self::SERVICE_MAP => String::from("service_map"),
20            Self::UnparsedObject(v) => v.value.to_string(),
21        }
22    }
23}
24
25impl Serialize for TopologyQueryDataSource {
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 TopologyQueryDataSource {
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            "data_streams" => Self::DATA_STREAMS,
45            "service_map" => Self::SERVICE_MAP,
46            _ => Self::UnparsedObject(crate::datadog::UnparsedObject {
47                value: serde_json::Value::String(s.into()),
48            }),
49        })
50    }
51}