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