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