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