stripe_shared/
payment_intent_payment_method_options_swish.rs1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentIntentPaymentMethodOptionsSwish {
5 pub reference: Option<String>,
7 pub setup_future_usage: Option<PaymentIntentPaymentMethodOptionsSwishSetupFutureUsage>,
16}
17#[doc(hidden)]
18pub struct PaymentIntentPaymentMethodOptionsSwishBuilder {
19 reference: Option<Option<String>>,
20 setup_future_usage: Option<Option<PaymentIntentPaymentMethodOptionsSwishSetupFutureUsage>>,
21}
22
23#[allow(
24 unused_variables,
25 irrefutable_let_patterns,
26 clippy::let_unit_value,
27 clippy::match_single_binding,
28 clippy::single_match
29)]
30const _: () = {
31 use miniserde::de::{Map, Visitor};
32 use miniserde::json::Value;
33 use miniserde::{Deserialize, Result, make_place};
34 use stripe_types::miniserde_helpers::FromValueOpt;
35 use stripe_types::{MapBuilder, ObjectDeser};
36
37 make_place!(Place);
38
39 impl Deserialize for PaymentIntentPaymentMethodOptionsSwish {
40 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
41 Place::new(out)
42 }
43 }
44
45 struct Builder<'a> {
46 out: &'a mut Option<PaymentIntentPaymentMethodOptionsSwish>,
47 builder: PaymentIntentPaymentMethodOptionsSwishBuilder,
48 }
49
50 impl Visitor for Place<PaymentIntentPaymentMethodOptionsSwish> {
51 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
52 Ok(Box::new(Builder {
53 out: &mut self.out,
54 builder: PaymentIntentPaymentMethodOptionsSwishBuilder::deser_default(),
55 }))
56 }
57 }
58
59 impl MapBuilder for PaymentIntentPaymentMethodOptionsSwishBuilder {
60 type Out = PaymentIntentPaymentMethodOptionsSwish;
61 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
62 Ok(match k {
63 "reference" => Deserialize::begin(&mut self.reference),
64 "setup_future_usage" => Deserialize::begin(&mut self.setup_future_usage),
65 _ => <dyn Visitor>::ignore(),
66 })
67 }
68
69 fn deser_default() -> Self {
70 Self { reference: Deserialize::default(), setup_future_usage: Deserialize::default() }
71 }
72
73 fn take_out(&mut self) -> Option<Self::Out> {
74 let (Some(reference), Some(setup_future_usage)) =
75 (self.reference.take(), self.setup_future_usage.take())
76 else {
77 return None;
78 };
79 Some(Self::Out { reference, setup_future_usage })
80 }
81 }
82
83 impl Map for Builder<'_> {
84 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
85 self.builder.key(k)
86 }
87
88 fn finish(&mut self) -> Result<()> {
89 *self.out = self.builder.take_out();
90 Ok(())
91 }
92 }
93
94 impl ObjectDeser for PaymentIntentPaymentMethodOptionsSwish {
95 type Builder = PaymentIntentPaymentMethodOptionsSwishBuilder;
96 }
97
98 impl FromValueOpt for PaymentIntentPaymentMethodOptionsSwish {
99 fn from_value(v: Value) -> Option<Self> {
100 let Value::Object(obj) = v else {
101 return None;
102 };
103 let mut b = PaymentIntentPaymentMethodOptionsSwishBuilder::deser_default();
104 for (k, v) in obj {
105 match k.as_str() {
106 "reference" => b.reference = FromValueOpt::from_value(v),
107 "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
108 _ => {}
109 }
110 }
111 b.take_out()
112 }
113 }
114};
115#[derive(Clone, Eq, PartialEq)]
124#[non_exhaustive]
125pub enum PaymentIntentPaymentMethodOptionsSwishSetupFutureUsage {
126 None,
127 Unknown(String),
129}
130impl PaymentIntentPaymentMethodOptionsSwishSetupFutureUsage {
131 pub fn as_str(&self) -> &str {
132 use PaymentIntentPaymentMethodOptionsSwishSetupFutureUsage::*;
133 match self {
134 None => "none",
135 Unknown(v) => v,
136 }
137 }
138}
139
140impl std::str::FromStr for PaymentIntentPaymentMethodOptionsSwishSetupFutureUsage {
141 type Err = std::convert::Infallible;
142 fn from_str(s: &str) -> Result<Self, Self::Err> {
143 use PaymentIntentPaymentMethodOptionsSwishSetupFutureUsage::*;
144 match s {
145 "none" => Ok(None),
146 v => {
147 tracing::warn!(
148 "Unknown value '{}' for enum '{}'",
149 v,
150 "PaymentIntentPaymentMethodOptionsSwishSetupFutureUsage"
151 );
152 Ok(Unknown(v.to_owned()))
153 }
154 }
155 }
156}
157impl std::fmt::Display for PaymentIntentPaymentMethodOptionsSwishSetupFutureUsage {
158 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
159 f.write_str(self.as_str())
160 }
161}
162
163impl std::fmt::Debug for PaymentIntentPaymentMethodOptionsSwishSetupFutureUsage {
164 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
165 f.write_str(self.as_str())
166 }
167}
168#[cfg(feature = "serialize")]
169impl serde::Serialize for PaymentIntentPaymentMethodOptionsSwishSetupFutureUsage {
170 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
171 where
172 S: serde::Serializer,
173 {
174 serializer.serialize_str(self.as_str())
175 }
176}
177impl miniserde::Deserialize for PaymentIntentPaymentMethodOptionsSwishSetupFutureUsage {
178 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
179 crate::Place::new(out)
180 }
181}
182
183impl miniserde::de::Visitor
184 for crate::Place<PaymentIntentPaymentMethodOptionsSwishSetupFutureUsage>
185{
186 fn string(&mut self, s: &str) -> miniserde::Result<()> {
187 use std::str::FromStr;
188 self.out = Some(
189 PaymentIntentPaymentMethodOptionsSwishSetupFutureUsage::from_str(s)
190 .expect("infallible"),
191 );
192 Ok(())
193 }
194}
195
196stripe_types::impl_from_val_with_from_str!(PaymentIntentPaymentMethodOptionsSwishSetupFutureUsage);
197#[cfg(feature = "deserialize")]
198impl<'de> serde::Deserialize<'de> for PaymentIntentPaymentMethodOptionsSwishSetupFutureUsage {
199 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
200 use std::str::FromStr;
201 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
202 Ok(Self::from_str(&s).expect("infallible"))
203 }
204}