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