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