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