stripe_shared/
tax_i_ds_owner.rs1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct TaxIDsOwner {
5 pub account: Option<stripe_types::Expandable<stripe_shared::Account>>,
7 pub application: Option<stripe_types::Expandable<stripe_shared::Application>>,
9 pub customer: Option<stripe_types::Expandable<stripe_shared::Customer>>,
11 #[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
68 _ => <dyn Visitor>::ignore(),
69 })
70 }
71
72 fn deser_default() -> Self {
73 Self {
74 account: Deserialize::default(),
75 application: Deserialize::default(),
76 customer: Deserialize::default(),
77 type_: Deserialize::default(),
78 }
79 }
80
81 fn take_out(&mut self) -> Option<Self::Out> {
82 let (Some(account), Some(application), Some(customer), Some(type_)) =
83 (self.account.take(), self.application.take(), self.customer.take(), self.type_)
84 else {
85 return None;
86 };
87 Some(Self::Out { account, application, customer, type_ })
88 }
89 }
90
91 impl Map for Builder<'_> {
92 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
93 self.builder.key(k)
94 }
95
96 fn finish(&mut self) -> Result<()> {
97 *self.out = self.builder.take_out();
98 Ok(())
99 }
100 }
101
102 impl ObjectDeser for TaxIDsOwner {
103 type Builder = TaxIDsOwnerBuilder;
104 }
105
106 impl FromValueOpt for TaxIDsOwner {
107 fn from_value(v: Value) -> Option<Self> {
108 let Value::Object(obj) = v else {
109 return None;
110 };
111 let mut b = TaxIDsOwnerBuilder::deser_default();
112 for (k, v) in obj {
113 match k.as_str() {
114 "account" => b.account = FromValueOpt::from_value(v),
115 "application" => b.application = FromValueOpt::from_value(v),
116 "customer" => b.customer = FromValueOpt::from_value(v),
117 "type" => b.type_ = FromValueOpt::from_value(v),
118
119 _ => {}
120 }
121 }
122 b.take_out()
123 }
124 }
125};
126#[derive(Copy, Clone, Eq, PartialEq)]
128pub enum TaxIDsOwnerType {
129 Account,
130 Application,
131 Customer,
132 Self_,
133}
134impl TaxIDsOwnerType {
135 pub fn as_str(self) -> &'static str {
136 use TaxIDsOwnerType::*;
137 match self {
138 Account => "account",
139 Application => "application",
140 Customer => "customer",
141 Self_ => "self",
142 }
143 }
144}
145
146impl std::str::FromStr for TaxIDsOwnerType {
147 type Err = stripe_types::StripeParseError;
148 fn from_str(s: &str) -> Result<Self, Self::Err> {
149 use TaxIDsOwnerType::*;
150 match s {
151 "account" => Ok(Account),
152 "application" => Ok(Application),
153 "customer" => Ok(Customer),
154 "self" => Ok(Self_),
155 _ => Err(stripe_types::StripeParseError),
156 }
157 }
158}
159impl std::fmt::Display for TaxIDsOwnerType {
160 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
161 f.write_str(self.as_str())
162 }
163}
164
165impl std::fmt::Debug for TaxIDsOwnerType {
166 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
167 f.write_str(self.as_str())
168 }
169}
170#[cfg(feature = "serialize")]
171impl serde::Serialize for TaxIDsOwnerType {
172 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
173 where
174 S: serde::Serializer,
175 {
176 serializer.serialize_str(self.as_str())
177 }
178}
179impl miniserde::Deserialize for TaxIDsOwnerType {
180 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
181 crate::Place::new(out)
182 }
183}
184
185impl miniserde::de::Visitor for crate::Place<TaxIDsOwnerType> {
186 fn string(&mut self, s: &str) -> miniserde::Result<()> {
187 use std::str::FromStr;
188 self.out = Some(TaxIDsOwnerType::from_str(s).map_err(|_| miniserde::Error)?);
189 Ok(())
190 }
191}
192
193stripe_types::impl_from_val_with_from_str!(TaxIDsOwnerType);
194#[cfg(feature = "deserialize")]
195impl<'de> serde::Deserialize<'de> for TaxIDsOwnerType {
196 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
197 use std::str::FromStr;
198 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
199 Self::from_str(&s)
200 .map_err(|_| serde::de::Error::custom("Unknown value for TaxIDsOwnerType"))
201 }
202}