stripe_shared/
payment_method_options_customer_balance_eu_bank_account.rs

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