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