stripe_shared/
payment_method_details_passthrough_card.rs1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentMethodDetailsPassthroughCard {
5 pub brand: Option<String>,
8 pub country: Option<String>,
11 pub exp_month: Option<i64>,
13 pub exp_year: Option<i64>,
15 pub funding: Option<String>,
17 pub last4: Option<String>,
19}
20#[doc(hidden)]
21pub struct PaymentMethodDetailsPassthroughCardBuilder {
22 brand: Option<Option<String>>,
23 country: Option<Option<String>>,
24 exp_month: Option<Option<i64>>,
25 exp_year: Option<Option<i64>>,
26 funding: Option<Option<String>>,
27 last4: Option<Option<String>>,
28}
29
30#[allow(
31 unused_variables,
32 irrefutable_let_patterns,
33 clippy::let_unit_value,
34 clippy::match_single_binding,
35 clippy::single_match
36)]
37const _: () = {
38 use miniserde::de::{Map, Visitor};
39 use miniserde::json::Value;
40 use miniserde::{Deserialize, Result, make_place};
41 use stripe_types::miniserde_helpers::FromValueOpt;
42 use stripe_types::{MapBuilder, ObjectDeser};
43
44 make_place!(Place);
45
46 impl Deserialize for PaymentMethodDetailsPassthroughCard {
47 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
48 Place::new(out)
49 }
50 }
51
52 struct Builder<'a> {
53 out: &'a mut Option<PaymentMethodDetailsPassthroughCard>,
54 builder: PaymentMethodDetailsPassthroughCardBuilder,
55 }
56
57 impl Visitor for Place<PaymentMethodDetailsPassthroughCard> {
58 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
59 Ok(Box::new(Builder {
60 out: &mut self.out,
61 builder: PaymentMethodDetailsPassthroughCardBuilder::deser_default(),
62 }))
63 }
64 }
65
66 impl MapBuilder for PaymentMethodDetailsPassthroughCardBuilder {
67 type Out = PaymentMethodDetailsPassthroughCard;
68 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
69 Ok(match k {
70 "brand" => Deserialize::begin(&mut self.brand),
71 "country" => Deserialize::begin(&mut self.country),
72 "exp_month" => Deserialize::begin(&mut self.exp_month),
73 "exp_year" => Deserialize::begin(&mut self.exp_year),
74 "funding" => Deserialize::begin(&mut self.funding),
75 "last4" => Deserialize::begin(&mut self.last4),
76
77 _ => <dyn Visitor>::ignore(),
78 })
79 }
80
81 fn deser_default() -> Self {
82 Self {
83 brand: Deserialize::default(),
84 country: Deserialize::default(),
85 exp_month: Deserialize::default(),
86 exp_year: Deserialize::default(),
87 funding: Deserialize::default(),
88 last4: Deserialize::default(),
89 }
90 }
91
92 fn take_out(&mut self) -> Option<Self::Out> {
93 let (
94 Some(brand),
95 Some(country),
96 Some(exp_month),
97 Some(exp_year),
98 Some(funding),
99 Some(last4),
100 ) = (
101 self.brand.take(),
102 self.country.take(),
103 self.exp_month,
104 self.exp_year,
105 self.funding.take(),
106 self.last4.take(),
107 )
108 else {
109 return None;
110 };
111 Some(Self::Out { brand, country, exp_month, exp_year, funding, last4 })
112 }
113 }
114
115 impl Map for Builder<'_> {
116 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
117 self.builder.key(k)
118 }
119
120 fn finish(&mut self) -> Result<()> {
121 *self.out = self.builder.take_out();
122 Ok(())
123 }
124 }
125
126 impl ObjectDeser for PaymentMethodDetailsPassthroughCard {
127 type Builder = PaymentMethodDetailsPassthroughCardBuilder;
128 }
129
130 impl FromValueOpt for PaymentMethodDetailsPassthroughCard {
131 fn from_value(v: Value) -> Option<Self> {
132 let Value::Object(obj) = v else {
133 return None;
134 };
135 let mut b = PaymentMethodDetailsPassthroughCardBuilder::deser_default();
136 for (k, v) in obj {
137 match k.as_str() {
138 "brand" => b.brand = FromValueOpt::from_value(v),
139 "country" => b.country = FromValueOpt::from_value(v),
140 "exp_month" => b.exp_month = FromValueOpt::from_value(v),
141 "exp_year" => b.exp_year = FromValueOpt::from_value(v),
142 "funding" => b.funding = FromValueOpt::from_value(v),
143 "last4" => b.last4 = FromValueOpt::from_value(v),
144
145 _ => {}
146 }
147 }
148 b.take_out()
149 }
150 }
151};