datadog_api_client/datadogV2/model/
model_interface_attributes_status.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 InterfaceAttributesStatus {
10    UP,
11    DOWN,
12    WARNING,
13    OFF,
14    UnparsedObject(crate::datadog::UnparsedObject),
15}
16
17impl ToString for InterfaceAttributesStatus {
18    fn to_string(&self) -> String {
19        match self {
20            Self::UP => String::from("up"),
21            Self::DOWN => String::from("down"),
22            Self::WARNING => String::from("warning"),
23            Self::OFF => String::from("off"),
24            Self::UnparsedObject(v) => v.value.to_string(),
25        }
26    }
27}
28
29impl Serialize for InterfaceAttributesStatus {
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 InterfaceAttributesStatus {
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            "up" => Self::UP,
49            "down" => Self::DOWN,
50            "warning" => Self::WARNING,
51            "off" => Self::OFF,
52            _ => Self::UnparsedObject(crate::datadog::UnparsedObject {
53                value: serde_json::Value::String(s.into()),
54            }),
55        })
56    }
57}