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::{Deserialize, Result, make_place};
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 _ => <dyn Visitor>::ignore(),
61 })
62 }
63
64 fn deser_default() -> Self {
65 Self { bank_transfer: Deserialize::default(), funding_type: Deserialize::default() }
66 }
67
68 fn take_out(&mut self) -> Option<Self::Out> {
69 let (Some(bank_transfer), Some(funding_type)) =
70 (self.bank_transfer.take(), self.funding_type)
71 else {
72 return None;
73 };
74 Some(Self::Out { bank_transfer, funding_type })
75 }
76 }
77
78 impl Map for Builder<'_> {
79 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
80 self.builder.key(k)
81 }
82
83 fn finish(&mut self) -> Result<()> {
84 *self.out = self.builder.take_out();
85 Ok(())
86 }
87 }
88
89 impl ObjectDeser for InvoicePaymentMethodOptionsCustomerBalance {
90 type Builder = InvoicePaymentMethodOptionsCustomerBalanceBuilder;
91 }
92
93 impl FromValueOpt for InvoicePaymentMethodOptionsCustomerBalance {
94 fn from_value(v: Value) -> Option<Self> {
95 let Value::Object(obj) = v else {
96 return None;
97 };
98 let mut b = InvoicePaymentMethodOptionsCustomerBalanceBuilder::deser_default();
99 for (k, v) in obj {
100 match k.as_str() {
101 "bank_transfer" => b.bank_transfer = FromValueOpt::from_value(v),
102 "funding_type" => b.funding_type = FromValueOpt::from_value(v),
103 _ => {}
104 }
105 }
106 b.take_out()
107 }
108 }
109};
110#[derive(Copy, Clone, Eq, PartialEq)]
113pub enum InvoicePaymentMethodOptionsCustomerBalanceFundingType {
114 BankTransfer,
115}
116impl InvoicePaymentMethodOptionsCustomerBalanceFundingType {
117 pub fn as_str(self) -> &'static str {
118 use InvoicePaymentMethodOptionsCustomerBalanceFundingType::*;
119 match self {
120 BankTransfer => "bank_transfer",
121 }
122 }
123}
124
125impl std::str::FromStr for InvoicePaymentMethodOptionsCustomerBalanceFundingType {
126 type Err = stripe_types::StripeParseError;
127 fn from_str(s: &str) -> Result<Self, Self::Err> {
128 use InvoicePaymentMethodOptionsCustomerBalanceFundingType::*;
129 match s {
130 "bank_transfer" => Ok(BankTransfer),
131 _ => Err(stripe_types::StripeParseError),
132 }
133 }
134}
135impl std::fmt::Display for InvoicePaymentMethodOptionsCustomerBalanceFundingType {
136 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
137 f.write_str(self.as_str())
138 }
139}
140
141impl std::fmt::Debug for InvoicePaymentMethodOptionsCustomerBalanceFundingType {
142 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
143 f.write_str(self.as_str())
144 }
145}
146#[cfg(feature = "serialize")]
147impl serde::Serialize for InvoicePaymentMethodOptionsCustomerBalanceFundingType {
148 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
149 where
150 S: serde::Serializer,
151 {
152 serializer.serialize_str(self.as_str())
153 }
154}
155impl miniserde::Deserialize for InvoicePaymentMethodOptionsCustomerBalanceFundingType {
156 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
157 crate::Place::new(out)
158 }
159}
160
161impl miniserde::de::Visitor
162 for crate::Place<InvoicePaymentMethodOptionsCustomerBalanceFundingType>
163{
164 fn string(&mut self, s: &str) -> miniserde::Result<()> {
165 use std::str::FromStr;
166 self.out = Some(
167 InvoicePaymentMethodOptionsCustomerBalanceFundingType::from_str(s)
168 .map_err(|_| miniserde::Error)?,
169 );
170 Ok(())
171 }
172}
173
174stripe_types::impl_from_val_with_from_str!(InvoicePaymentMethodOptionsCustomerBalanceFundingType);
175#[cfg(feature = "deserialize")]
176impl<'de> serde::Deserialize<'de> for InvoicePaymentMethodOptionsCustomerBalanceFundingType {
177 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
178 use std::str::FromStr;
179 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
180 Self::from_str(&s).map_err(|_| {
181 serde::de::Error::custom(
182 "Unknown value for InvoicePaymentMethodOptionsCustomerBalanceFundingType",
183 )
184 })
185 }
186}