datadog_api_client/datadogV2/model/
model_spec_version.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 SpecVersion {
10    ONE_ZERO,
11    ONE_ONE,
12    ONE_TWO,
13    ONE_THREE,
14    ONE_FOUR,
15    ONE_FIVE,
16    UnparsedObject(crate::datadog::UnparsedObject),
17}
18
19impl ToString for SpecVersion {
20    fn to_string(&self) -> String {
21        match self {
22            Self::ONE_ZERO => String::from("1.0"),
23            Self::ONE_ONE => String::from("1.1"),
24            Self::ONE_TWO => String::from("1.2"),
25            Self::ONE_THREE => String::from("1.3"),
26            Self::ONE_FOUR => String::from("1.4"),
27            Self::ONE_FIVE => String::from("1.5"),
28            Self::UnparsedObject(v) => v.value.to_string(),
29        }
30    }
31}
32
33impl Serialize for SpecVersion {
34    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
35    where
36        S: Serializer,
37    {
38        match self {
39            Self::UnparsedObject(v) => v.serialize(serializer),
40            _ => serializer.serialize_str(self.to_string().as_str()),
41        }
42    }
43}
44
45impl<'de> Deserialize<'de> for SpecVersion {
46    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
47    where
48        D: Deserializer<'de>,
49    {
50        let s: String = String::deserialize(deserializer)?;
51        Ok(match s.as_str() {
52            "1.0" => Self::ONE_ZERO,
53            "1.1" => Self::ONE_ONE,
54            "1.2" => Self::ONE_TWO,
55            "1.3" => Self::ONE_THREE,
56            "1.4" => Self::ONE_FOUR,
57            "1.5" => Self::ONE_FIVE,
58            _ => Self::UnparsedObject(crate::datadog::UnparsedObject {
59                value: serde_json::Value::String(s.into()),
60            }),
61        })
62    }
63}