use serde::de::{Error, MapAccess, Visitor};
use serde::{Deserialize, Deserializer, Serialize};
use serde_with::skip_serializing_none;
use std::fmt::{self, Formatter};
#[non_exhaustive]
#[skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct WidgetLegacyLiveSpan {
#[serde(rename = "hide_incomplete_cost_data")]
pub hide_incomplete_cost_data: Option<bool>,
#[serde(rename = "live_span")]
pub live_span: Option<crate::datadogV1::model::WidgetLiveSpan>,
#[serde(skip)]
#[serde(default)]
pub(crate) _unparsed: bool,
}
impl WidgetLegacyLiveSpan {
pub fn new() -> WidgetLegacyLiveSpan {
WidgetLegacyLiveSpan {
hide_incomplete_cost_data: None,
live_span: None,
_unparsed: false,
}
}
pub fn hide_incomplete_cost_data(mut self, value: bool) -> Self {
self.hide_incomplete_cost_data = Some(value);
self
}
pub fn live_span(mut self, value: crate::datadogV1::model::WidgetLiveSpan) -> Self {
self.live_span = Some(value);
self
}
}
impl Default for WidgetLegacyLiveSpan {
fn default() -> Self {
Self::new()
}
}
impl<'de> Deserialize<'de> for WidgetLegacyLiveSpan {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct WidgetLegacyLiveSpanVisitor;
impl<'a> Visitor<'a> for WidgetLegacyLiveSpanVisitor {
type Value = WidgetLegacyLiveSpan;
fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str("a mapping")
}
fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
where
M: MapAccess<'a>,
{
let mut hide_incomplete_cost_data: Option<bool> = None;
let mut live_span: Option<crate::datadogV1::model::WidgetLiveSpan> = None;
let mut _unparsed = false;
while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
match k.as_str() {
"hide_incomplete_cost_data" => {
if v.is_null() {
continue;
}
hide_incomplete_cost_data =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"live_span" => {
if v.is_null() {
continue;
}
live_span = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
if let Some(ref _live_span) = live_span {
match _live_span {
crate::datadogV1::model::WidgetLiveSpan::UnparsedObject(
_live_span,
) => {
_unparsed = true;
}
_ => {}
}
}
}
&_ => {
return Err(serde::de::Error::custom(
"Additional properties not allowed",
));
}
}
}
let content = WidgetLegacyLiveSpan {
hide_incomplete_cost_data,
live_span,
_unparsed,
};
Ok(content)
}
}
deserializer.deserialize_any(WidgetLegacyLiveSpanVisitor)
}
}