stripe_misc/tax_association/
types.rs1#[derive(Clone, Debug)]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct TaxAssociation {
5 pub calculation: String,
7 pub id: stripe_misc::TaxAssociationId,
9 pub payment_intent: String,
11 pub tax_transaction_attempts:
13 Option<Vec<stripe_misc::TaxProductResourceTaxAssociationTransactionAttempts>>,
14}
15#[doc(hidden)]
16pub struct TaxAssociationBuilder {
17 calculation: Option<String>,
18 id: Option<stripe_misc::TaxAssociationId>,
19 payment_intent: Option<String>,
20 tax_transaction_attempts:
21 Option<Option<Vec<stripe_misc::TaxProductResourceTaxAssociationTransactionAttempts>>>,
22}
23
24#[allow(
25 unused_variables,
26 irrefutable_let_patterns,
27 clippy::let_unit_value,
28 clippy::match_single_binding,
29 clippy::single_match
30)]
31const _: () = {
32 use miniserde::de::{Map, Visitor};
33 use miniserde::json::Value;
34 use miniserde::{Deserialize, Result, make_place};
35 use stripe_types::miniserde_helpers::FromValueOpt;
36 use stripe_types::{MapBuilder, ObjectDeser};
37
38 make_place!(Place);
39
40 impl Deserialize for TaxAssociation {
41 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
42 Place::new(out)
43 }
44 }
45
46 struct Builder<'a> {
47 out: &'a mut Option<TaxAssociation>,
48 builder: TaxAssociationBuilder,
49 }
50
51 impl Visitor for Place<TaxAssociation> {
52 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
53 Ok(Box::new(Builder {
54 out: &mut self.out,
55 builder: TaxAssociationBuilder::deser_default(),
56 }))
57 }
58 }
59
60 impl MapBuilder for TaxAssociationBuilder {
61 type Out = TaxAssociation;
62 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
63 Ok(match k {
64 "calculation" => Deserialize::begin(&mut self.calculation),
65 "id" => Deserialize::begin(&mut self.id),
66 "payment_intent" => Deserialize::begin(&mut self.payment_intent),
67 "tax_transaction_attempts" => {
68 Deserialize::begin(&mut self.tax_transaction_attempts)
69 }
70 _ => <dyn Visitor>::ignore(),
71 })
72 }
73
74 fn deser_default() -> Self {
75 Self {
76 calculation: Deserialize::default(),
77 id: Deserialize::default(),
78 payment_intent: Deserialize::default(),
79 tax_transaction_attempts: Deserialize::default(),
80 }
81 }
82
83 fn take_out(&mut self) -> Option<Self::Out> {
84 let (Some(calculation), Some(id), Some(payment_intent), Some(tax_transaction_attempts)) = (
85 self.calculation.take(),
86 self.id.take(),
87 self.payment_intent.take(),
88 self.tax_transaction_attempts.take(),
89 ) else {
90 return None;
91 };
92 Some(Self::Out { calculation, id, payment_intent, tax_transaction_attempts })
93 }
94 }
95
96 impl Map for Builder<'_> {
97 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
98 self.builder.key(k)
99 }
100
101 fn finish(&mut self) -> Result<()> {
102 *self.out = self.builder.take_out();
103 Ok(())
104 }
105 }
106
107 impl ObjectDeser for TaxAssociation {
108 type Builder = TaxAssociationBuilder;
109 }
110
111 impl FromValueOpt for TaxAssociation {
112 fn from_value(v: Value) -> Option<Self> {
113 let Value::Object(obj) = v else {
114 return None;
115 };
116 let mut b = TaxAssociationBuilder::deser_default();
117 for (k, v) in obj {
118 match k.as_str() {
119 "calculation" => b.calculation = FromValueOpt::from_value(v),
120 "id" => b.id = FromValueOpt::from_value(v),
121 "payment_intent" => b.payment_intent = FromValueOpt::from_value(v),
122 "tax_transaction_attempts" => {
123 b.tax_transaction_attempts = FromValueOpt::from_value(v)
124 }
125 _ => {}
126 }
127 }
128 b.take_out()
129 }
130 }
131};
132#[cfg(feature = "serialize")]
133impl serde::Serialize for TaxAssociation {
134 fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
135 use serde::ser::SerializeStruct;
136 let mut s = s.serialize_struct("TaxAssociation", 5)?;
137 s.serialize_field("calculation", &self.calculation)?;
138 s.serialize_field("id", &self.id)?;
139 s.serialize_field("payment_intent", &self.payment_intent)?;
140 s.serialize_field("tax_transaction_attempts", &self.tax_transaction_attempts)?;
141
142 s.serialize_field("object", "tax.association")?;
143 s.end()
144 }
145}
146impl stripe_types::Object for TaxAssociation {
147 type Id = stripe_misc::TaxAssociationId;
148 fn id(&self) -> &Self::Id {
149 &self.id
150 }
151
152 fn into_id(self) -> Self::Id {
153 self.id
154 }
155}
156stripe_types::def_id!(TaxAssociationId);