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::{Deserialize, Result, make_place};
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 _ => <dyn Visitor>::ignore(),
70 })
71 }
72
73 fn deser_default() -> Self {
74 Self { object: Deserialize::default(), previous_attributes: Deserialize::default() }
75 }
76
77 fn take_out(&mut self) -> Option<Self::Out> {
78 let (Some(object), Some(previous_attributes)) =
79 (self.object.take(), self.previous_attributes.take())
80 else {
81 return None;
82 };
83 Some(Self::Out { object, previous_attributes })
84 }
85 }
86
87 impl Map for Builder<'_> {
88 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
89 self.builder.key(k)
90 }
91
92 fn finish(&mut self) -> Result<()> {
93 *self.out = self.builder.take_out();
94 Ok(())
95 }
96 }
97
98 impl ObjectDeser for NotificationEventData {
99 type Builder = NotificationEventDataBuilder;
100 }
101
102 impl FromValueOpt for NotificationEventData {
103 fn from_value(v: Value) -> Option<Self> {
104 let Value::Object(obj) = v else {
105 return None;
106 };
107 let mut b = NotificationEventDataBuilder::deser_default();
108 for (k, v) in obj {
109 match k.as_str() {
110 "object" => b.object = FromValueOpt::from_value(v),
111 "previous_attributes" => b.previous_attributes = FromValueOpt::from_value(v),
112 _ => {}
113 }
114 }
115 b.take_out()
116 }
117 }
118};