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