datadog_api_client/datadogV1/model/
model_logs_grok_parser_rules.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 LogsGrokParserRules {
14 #[serde(rename = "match_rules")]
16 pub match_rules: String,
17 #[serde(rename = "support_rules")]
19 pub support_rules: Option<String>,
20 #[serde(flatten)]
21 pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
22 #[serde(skip)]
23 #[serde(default)]
24 pub(crate) _unparsed: bool,
25}
26
27impl LogsGrokParserRules {
28 pub fn new(match_rules: String) -> LogsGrokParserRules {
29 LogsGrokParserRules {
30 match_rules,
31 support_rules: None,
32 additional_properties: std::collections::BTreeMap::new(),
33 _unparsed: false,
34 }
35 }
36
37 pub fn support_rules(mut self, value: String) -> Self {
38 self.support_rules = Some(value);
39 self
40 }
41
42 pub fn additional_properties(
43 mut self,
44 value: std::collections::BTreeMap<String, serde_json::Value>,
45 ) -> Self {
46 self.additional_properties = value;
47 self
48 }
49}
50
51impl<'de> Deserialize<'de> for LogsGrokParserRules {
52 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
53 where
54 D: Deserializer<'de>,
55 {
56 struct LogsGrokParserRulesVisitor;
57 impl<'a> Visitor<'a> for LogsGrokParserRulesVisitor {
58 type Value = LogsGrokParserRules;
59
60 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
61 f.write_str("a mapping")
62 }
63
64 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
65 where
66 M: MapAccess<'a>,
67 {
68 let mut match_rules: Option<String> = None;
69 let mut support_rules: Option<String> = None;
70 let mut additional_properties: std::collections::BTreeMap<
71 String,
72 serde_json::Value,
73 > = std::collections::BTreeMap::new();
74 let mut _unparsed = false;
75
76 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
77 match k.as_str() {
78 "match_rules" => {
79 match_rules =
80 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
81 }
82 "support_rules" => {
83 if v.is_null() {
84 continue;
85 }
86 support_rules =
87 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
88 }
89 &_ => {
90 if let Ok(value) = serde_json::from_value(v.clone()) {
91 additional_properties.insert(k, value);
92 }
93 }
94 }
95 }
96 let match_rules =
97 match_rules.ok_or_else(|| M::Error::missing_field("match_rules"))?;
98
99 let content = LogsGrokParserRules {
100 match_rules,
101 support_rules,
102 additional_properties,
103 _unparsed,
104 };
105
106 Ok(content)
107 }
108 }
109
110 deserializer.deserialize_any(LogsGrokParserRulesVisitor)
111 }
112}