stripe_shared/
notification_event_data.rs1#[derive(Clone)]
2#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct NotificationEventData {
6 #[cfg_attr(
9 any(feature = "deserialize", feature = "serialize"),
10 serde(with = "stripe_types::with_serde_json")
11 )]
12 pub object: miniserde::json::Value,
13 #[cfg_attr(
17 any(feature = "deserialize", feature = "serialize"),
18 serde(with = "stripe_types::with_serde_json_opt")
19 )]
20 pub previous_attributes: Option<miniserde::json::Value>,
21}
22#[cfg(feature = "redact-generated-debug")]
23impl std::fmt::Debug for NotificationEventData {
24 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
25 f.debug_struct("NotificationEventData").finish_non_exhaustive()
26 }
27}
28#[doc(hidden)]
29pub struct NotificationEventDataBuilder {
30 object: Option<miniserde::json::Value>,
31 previous_attributes: Option<Option<miniserde::json::Value>>,
32}
33
34#[allow(
35 unused_variables,
36 irrefutable_let_patterns,
37 clippy::let_unit_value,
38 clippy::match_single_binding,
39 clippy::single_match
40)]
41const _: () = {
42 use miniserde::de::{Map, Visitor};
43 use miniserde::json::Value;
44 use miniserde::{Deserialize, Result, make_place};
45 use stripe_types::miniserde_helpers::FromValueOpt;
46 use stripe_types::{MapBuilder, ObjectDeser};
47
48 make_place!(Place);
49
50 impl Deserialize for NotificationEventData {
51 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
52 Place::new(out)
53 }
54 }
55
56 struct Builder<'a> {
57 out: &'a mut Option<NotificationEventData>,
58 builder: NotificationEventDataBuilder,
59 }
60
61 impl Visitor for Place<NotificationEventData> {
62 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
63 Ok(Box::new(Builder {
64 out: &mut self.out,
65 builder: NotificationEventDataBuilder::deser_default(),
66 }))
67 }
68 }
69
70 impl MapBuilder for NotificationEventDataBuilder {
71 type Out = NotificationEventData;
72 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
73 Ok(match k {
74 "object" => Deserialize::begin(&mut self.object),
75 "previous_attributes" => Deserialize::begin(&mut self.previous_attributes),
76 _ => <dyn Visitor>::ignore(),
77 })
78 }
79
80 fn deser_default() -> Self {
81 Self { object: Deserialize::default(), previous_attributes: Deserialize::default() }
82 }
83
84 fn take_out(&mut self) -> Option<Self::Out> {
85 let (Some(object), Some(previous_attributes)) =
86 (self.object.take(), self.previous_attributes.take())
87 else {
88 return None;
89 };
90 Some(Self::Out { object, previous_attributes })
91 }
92 }
93
94 impl Map for Builder<'_> {
95 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
96 self.builder.key(k)
97 }
98
99 fn finish(&mut self) -> Result<()> {
100 *self.out = self.builder.take_out();
101 Ok(())
102 }
103 }
104
105 impl ObjectDeser for NotificationEventData {
106 type Builder = NotificationEventDataBuilder;
107 }
108
109 impl FromValueOpt for NotificationEventData {
110 fn from_value(v: Value) -> Option<Self> {
111 let Value::Object(obj) = v else {
112 return None;
113 };
114 let mut b = NotificationEventDataBuilder::deser_default();
115 for (k, v) in obj {
116 match k.as_str() {
117 "object" => b.object = FromValueOpt::from_value(v),
118 "previous_attributes" => b.previous_attributes = FromValueOpt::from_value(v),
119 _ => {}
120 }
121 }
122 b.take_out()
123 }
124 }
125};