stripe_shared/
setup_attempt_payment_method_details_card_wallet.rs1#[derive(Clone, Eq, PartialEq)]
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 SetupAttemptPaymentMethodDetailsCardWallet {
6 pub apple_pay: Option<stripe_shared::PaymentMethodDetailsCardWalletApplePay>,
7 pub google_pay: Option<stripe_shared::PaymentMethodDetailsCardWalletGooglePay>,
8 #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
12 pub type_: SetupAttemptPaymentMethodDetailsCardWalletType,
13}
14#[cfg(feature = "redact-generated-debug")]
15impl std::fmt::Debug for SetupAttemptPaymentMethodDetailsCardWallet {
16 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
17 f.debug_struct("SetupAttemptPaymentMethodDetailsCardWallet").finish_non_exhaustive()
18 }
19}
20#[doc(hidden)]
21pub struct SetupAttemptPaymentMethodDetailsCardWalletBuilder {
22 apple_pay: Option<Option<stripe_shared::PaymentMethodDetailsCardWalletApplePay>>,
23 google_pay: Option<Option<stripe_shared::PaymentMethodDetailsCardWalletGooglePay>>,
24 type_: Option<SetupAttemptPaymentMethodDetailsCardWalletType>,
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 SetupAttemptPaymentMethodDetailsCardWallet {
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<SetupAttemptPaymentMethodDetailsCardWallet>,
51 builder: SetupAttemptPaymentMethodDetailsCardWalletBuilder,
52 }
53
54 impl Visitor for Place<SetupAttemptPaymentMethodDetailsCardWallet> {
55 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
56 Ok(Box::new(Builder {
57 out: &mut self.out,
58 builder: SetupAttemptPaymentMethodDetailsCardWalletBuilder::deser_default(),
59 }))
60 }
61 }
62
63 impl MapBuilder for SetupAttemptPaymentMethodDetailsCardWalletBuilder {
64 type Out = SetupAttemptPaymentMethodDetailsCardWallet;
65 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
66 Ok(match k {
67 "apple_pay" => Deserialize::begin(&mut self.apple_pay),
68 "google_pay" => Deserialize::begin(&mut self.google_pay),
69 "type" => Deserialize::begin(&mut self.type_),
70 _ => <dyn Visitor>::ignore(),
71 })
72 }
73
74 fn deser_default() -> Self {
75 Self { apple_pay: Some(None), google_pay: Some(None), type_: None }
76 }
77
78 fn take_out(&mut self) -> Option<Self::Out> {
79 let (Some(apple_pay), Some(google_pay), Some(type_)) =
80 (self.apple_pay, self.google_pay, self.type_.take())
81 else {
82 return None;
83 };
84 Some(Self::Out { apple_pay, google_pay, type_ })
85 }
86 }
87
88 impl Map for Builder<'_> {
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 SetupAttemptPaymentMethodDetailsCardWallet {
100 type Builder = SetupAttemptPaymentMethodDetailsCardWalletBuilder;
101 }
102
103 impl FromValueOpt for SetupAttemptPaymentMethodDetailsCardWallet {
104 fn from_value(v: Value) -> Option<Self> {
105 let Value::Object(obj) = v else {
106 return None;
107 };
108 let mut b = SetupAttemptPaymentMethodDetailsCardWalletBuilder::deser_default();
109 for (k, v) in obj {
110 match k.as_str() {
111 "apple_pay" => b.apple_pay = FromValueOpt::from_value(v),
112 "google_pay" => b.google_pay = FromValueOpt::from_value(v),
113 "type" => b.type_ = FromValueOpt::from_value(v),
114 _ => {}
115 }
116 }
117 b.take_out()
118 }
119 }
120};
121#[derive(Clone, Eq, PartialEq)]
125#[non_exhaustive]
126pub enum SetupAttemptPaymentMethodDetailsCardWalletType {
127 ApplePay,
128 GooglePay,
129 Link,
130 Unknown(String),
132}
133impl SetupAttemptPaymentMethodDetailsCardWalletType {
134 pub fn as_str(&self) -> &str {
135 use SetupAttemptPaymentMethodDetailsCardWalletType::*;
136 match self {
137 ApplePay => "apple_pay",
138 GooglePay => "google_pay",
139 Link => "link",
140 Unknown(v) => v,
141 }
142 }
143}
144
145impl std::str::FromStr for SetupAttemptPaymentMethodDetailsCardWalletType {
146 type Err = std::convert::Infallible;
147 fn from_str(s: &str) -> Result<Self, Self::Err> {
148 use SetupAttemptPaymentMethodDetailsCardWalletType::*;
149 match s {
150 "apple_pay" => Ok(ApplePay),
151 "google_pay" => Ok(GooglePay),
152 "link" => Ok(Link),
153 v => {
154 tracing::warn!(
155 "Unknown value '{}' for enum '{}'",
156 v,
157 "SetupAttemptPaymentMethodDetailsCardWalletType"
158 );
159 Ok(Unknown(v.to_owned()))
160 }
161 }
162 }
163}
164impl std::fmt::Display for SetupAttemptPaymentMethodDetailsCardWalletType {
165 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
166 f.write_str(self.as_str())
167 }
168}
169
170#[cfg(not(feature = "redact-generated-debug"))]
171impl std::fmt::Debug for SetupAttemptPaymentMethodDetailsCardWalletType {
172 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
173 f.write_str(self.as_str())
174 }
175}
176#[cfg(feature = "redact-generated-debug")]
177impl std::fmt::Debug for SetupAttemptPaymentMethodDetailsCardWalletType {
178 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
179 f.debug_struct(stringify!(SetupAttemptPaymentMethodDetailsCardWalletType))
180 .finish_non_exhaustive()
181 }
182}
183#[cfg(feature = "serialize")]
184impl serde::Serialize for SetupAttemptPaymentMethodDetailsCardWalletType {
185 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
186 where
187 S: serde::Serializer,
188 {
189 serializer.serialize_str(self.as_str())
190 }
191}
192impl miniserde::Deserialize for SetupAttemptPaymentMethodDetailsCardWalletType {
193 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
194 crate::Place::new(out)
195 }
196}
197
198impl miniserde::de::Visitor for crate::Place<SetupAttemptPaymentMethodDetailsCardWalletType> {
199 fn string(&mut self, s: &str) -> miniserde::Result<()> {
200 use std::str::FromStr;
201 self.out =
202 Some(SetupAttemptPaymentMethodDetailsCardWalletType::from_str(s).expect("infallible"));
203 Ok(())
204 }
205}
206
207stripe_types::impl_from_val_with_from_str!(SetupAttemptPaymentMethodDetailsCardWalletType);
208#[cfg(feature = "deserialize")]
209impl<'de> serde::Deserialize<'de> for SetupAttemptPaymentMethodDetailsCardWalletType {
210 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
211 use std::str::FromStr;
212 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
213 Ok(Self::from_str(&s).expect("infallible"))
214 }
215}