Skip to main content

stripe_shared/
tax_i_ds_owner.rs

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