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