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