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