datadog_api_client/datadogV1/model/
model_notebook_cell_create_request.rs1use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct NotebookCellCreateRequest {
14 #[serde(rename = "attributes")]
17 pub attributes: crate::datadogV1::model::NotebookCellCreateRequestAttributes,
18 #[serde(rename = "type")]
20 pub type_: crate::datadogV1::model::NotebookCellResourceType,
21 #[serde(skip)]
22 #[serde(default)]
23 pub(crate) _unparsed: bool,
24}
25
26impl NotebookCellCreateRequest {
27 pub fn new(
28 attributes: crate::datadogV1::model::NotebookCellCreateRequestAttributes,
29 type_: crate::datadogV1::model::NotebookCellResourceType,
30 ) -> NotebookCellCreateRequest {
31 NotebookCellCreateRequest {
32 attributes,
33 type_,
34 _unparsed: false,
35 }
36 }
37}
38
39impl<'de> Deserialize<'de> for NotebookCellCreateRequest {
40 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
41 where
42 D: Deserializer<'de>,
43 {
44 struct NotebookCellCreateRequestVisitor;
45 impl<'a> Visitor<'a> for NotebookCellCreateRequestVisitor {
46 type Value = NotebookCellCreateRequest;
47
48 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
49 f.write_str("a mapping")
50 }
51
52 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
53 where
54 M: MapAccess<'a>,
55 {
56 let mut attributes: Option<
57 crate::datadogV1::model::NotebookCellCreateRequestAttributes,
58 > = None;
59 let mut type_: Option<crate::datadogV1::model::NotebookCellResourceType> = None;
60 let mut _unparsed = false;
61
62 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
63 match k.as_str() {
64 "attributes" => {
65 attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
66 if let Some(ref _attributes) = attributes {
67 match _attributes {
68 crate::datadogV1::model::NotebookCellCreateRequestAttributes::UnparsedObject(_attributes) => {
69 _unparsed = true;
70 },
71 _ => {}
72 }
73 }
74 }
75 "type" => {
76 type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
77 if let Some(ref _type_) = type_ {
78 match _type_ {
79 crate::datadogV1::model::NotebookCellResourceType::UnparsedObject(_type_) => {
80 _unparsed = true;
81 },
82 _ => {}
83 }
84 }
85 }
86 &_ => {
87 return Err(serde::de::Error::custom(
88 "Additional properties not allowed",
89 ));
90 }
91 }
92 }
93 let attributes = attributes.ok_or_else(|| M::Error::missing_field("attributes"))?;
94 let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
95
96 let content = NotebookCellCreateRequest {
97 attributes,
98 type_,
99 _unparsed,
100 };
101
102 Ok(content)
103 }
104 }
105
106 deserializer.deserialize_any(NotebookCellCreateRequestVisitor)
107 }
108}