stripe_misc/
bank_connections_resource_accountholder.rs

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