datadog_api_client/datadogV1/model/
model_widget_line_width.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 WidgetLineWidth {
10    NORMAL,
11    THICK,
12    THIN,
13    UnparsedObject(crate::datadog::UnparsedObject),
14}
15
16impl ToString for WidgetLineWidth {
17    fn to_string(&self) -> String {
18        match self {
19            Self::NORMAL => String::from("normal"),
20            Self::THICK => String::from("thick"),
21            Self::THIN => String::from("thin"),
22            Self::UnparsedObject(v) => v.value.to_string(),
23        }
24    }
25}
26
27impl Serialize for WidgetLineWidth {
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 WidgetLineWidth {
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            "normal" => Self::NORMAL,
47            "thick" => Self::THICK,
48            "thin" => Self::THIN,
49            _ => Self::UnparsedObject(crate::datadog::UnparsedObject {
50                value: serde_json::Value::String(s.into()),
51            }),
52        })
53    }
54}