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