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