stripe_shared/
tax_i_ds_owner.rs

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