datadog_api_client/datadogV1/model/
model_notebook_markdown_cell_attributes.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.
4use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9/// The attributes of a notebook `markdown` cell.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct NotebookMarkdownCellAttributes {
14    /// Text in a notebook is formatted with [Markdown](<https://daringfireball.net/projects/markdown/>), which enables the use of headings, subheadings, links, images, lists, and code blocks.
15    #[serde(rename = "definition")]
16    pub definition: crate::datadogV1::model::NotebookMarkdownCellDefinition,
17    #[serde(flatten)]
18    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
19    #[serde(skip)]
20    #[serde(default)]
21    pub(crate) _unparsed: bool,
22}
23
24impl NotebookMarkdownCellAttributes {
25    pub fn new(
26        definition: crate::datadogV1::model::NotebookMarkdownCellDefinition,
27    ) -> NotebookMarkdownCellAttributes {
28        NotebookMarkdownCellAttributes {
29            definition,
30            additional_properties: std::collections::BTreeMap::new(),
31            _unparsed: false,
32        }
33    }
34
35    pub fn additional_properties(
36        mut self,
37        value: std::collections::BTreeMap<String, serde_json::Value>,
38    ) -> Self {
39        self.additional_properties = value;
40        self
41    }
42}
43
44impl<'de> Deserialize<'de> for NotebookMarkdownCellAttributes {
45    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
46    where
47        D: Deserializer<'de>,
48    {
49        struct NotebookMarkdownCellAttributesVisitor;
50        impl<'a> Visitor<'a> for NotebookMarkdownCellAttributesVisitor {
51            type Value = NotebookMarkdownCellAttributes;
52
53            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
54                f.write_str("a mapping")
55            }
56
57            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
58            where
59                M: MapAccess<'a>,
60            {
61                let mut definition: Option<
62                    crate::datadogV1::model::NotebookMarkdownCellDefinition,
63                > = None;
64                let mut additional_properties: std::collections::BTreeMap<
65                    String,
66                    serde_json::Value,
67                > = std::collections::BTreeMap::new();
68                let mut _unparsed = false;
69
70                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
71                    match k.as_str() {
72                        "definition" => {
73                            definition = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
74                        }
75                        &_ => {
76                            if let Ok(value) = serde_json::from_value(v.clone()) {
77                                additional_properties.insert(k, value);
78                            }
79                        }
80                    }
81                }
82                let definition = definition.ok_or_else(|| M::Error::missing_field("definition"))?;
83
84                let content = NotebookMarkdownCellAttributes {
85                    definition,
86                    additional_properties,
87                    _unparsed,
88                };
89
90                Ok(content)
91            }
92        }
93
94        deserializer.deserialize_any(NotebookMarkdownCellAttributesVisitor)
95    }
96}