1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentLinksResourceCustomFields {
5 pub dropdown: Option<stripe_shared::PaymentLinksResourceCustomFieldsDropdown>,
6 pub key: String,
9 pub label: stripe_shared::PaymentLinksResourceCustomFieldsLabel,
10 pub numeric: Option<stripe_shared::PaymentLinksResourceCustomFieldsNumeric>,
11 pub optional: bool,
14 pub text: Option<stripe_shared::PaymentLinksResourceCustomFieldsText>,
15 #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
17 pub type_: PaymentLinksResourceCustomFieldsType,
18}
19#[doc(hidden)]
20pub struct PaymentLinksResourceCustomFieldsBuilder {
21 dropdown: Option<Option<stripe_shared::PaymentLinksResourceCustomFieldsDropdown>>,
22 key: Option<String>,
23 label: Option<stripe_shared::PaymentLinksResourceCustomFieldsLabel>,
24 numeric: Option<Option<stripe_shared::PaymentLinksResourceCustomFieldsNumeric>>,
25 optional: Option<bool>,
26 text: Option<Option<stripe_shared::PaymentLinksResourceCustomFieldsText>>,
27 type_: Option<PaymentLinksResourceCustomFieldsType>,
28}
29
30#[allow(
31 unused_variables,
32 irrefutable_let_patterns,
33 clippy::let_unit_value,
34 clippy::match_single_binding,
35 clippy::single_match
36)]
37const _: () = {
38 use miniserde::de::{Map, Visitor};
39 use miniserde::json::Value;
40 use miniserde::{Deserialize, Result, make_place};
41 use stripe_types::miniserde_helpers::FromValueOpt;
42 use stripe_types::{MapBuilder, ObjectDeser};
43
44 make_place!(Place);
45
46 impl Deserialize for PaymentLinksResourceCustomFields {
47 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
48 Place::new(out)
49 }
50 }
51
52 struct Builder<'a> {
53 out: &'a mut Option<PaymentLinksResourceCustomFields>,
54 builder: PaymentLinksResourceCustomFieldsBuilder,
55 }
56
57 impl Visitor for Place<PaymentLinksResourceCustomFields> {
58 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
59 Ok(Box::new(Builder {
60 out: &mut self.out,
61 builder: PaymentLinksResourceCustomFieldsBuilder::deser_default(),
62 }))
63 }
64 }
65
66 impl MapBuilder for PaymentLinksResourceCustomFieldsBuilder {
67 type Out = PaymentLinksResourceCustomFields;
68 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
69 Ok(match k {
70 "dropdown" => Deserialize::begin(&mut self.dropdown),
71 "key" => Deserialize::begin(&mut self.key),
72 "label" => Deserialize::begin(&mut self.label),
73 "numeric" => Deserialize::begin(&mut self.numeric),
74 "optional" => Deserialize::begin(&mut self.optional),
75 "text" => Deserialize::begin(&mut self.text),
76 "type" => Deserialize::begin(&mut self.type_),
77 _ => <dyn Visitor>::ignore(),
78 })
79 }
80
81 fn deser_default() -> Self {
82 Self {
83 dropdown: Deserialize::default(),
84 key: Deserialize::default(),
85 label: Deserialize::default(),
86 numeric: Deserialize::default(),
87 optional: Deserialize::default(),
88 text: Deserialize::default(),
89 type_: Deserialize::default(),
90 }
91 }
92
93 fn take_out(&mut self) -> Option<Self::Out> {
94 let (
95 Some(dropdown),
96 Some(key),
97 Some(label),
98 Some(numeric),
99 Some(optional),
100 Some(text),
101 Some(type_),
102 ) = (
103 self.dropdown.take(),
104 self.key.take(),
105 self.label.take(),
106 self.numeric.take(),
107 self.optional,
108 self.text.take(),
109 self.type_.take(),
110 )
111 else {
112 return None;
113 };
114 Some(Self::Out { dropdown, key, label, numeric, optional, text, type_ })
115 }
116 }
117
118 impl Map for Builder<'_> {
119 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
120 self.builder.key(k)
121 }
122
123 fn finish(&mut self) -> Result<()> {
124 *self.out = self.builder.take_out();
125 Ok(())
126 }
127 }
128
129 impl ObjectDeser for PaymentLinksResourceCustomFields {
130 type Builder = PaymentLinksResourceCustomFieldsBuilder;
131 }
132
133 impl FromValueOpt for PaymentLinksResourceCustomFields {
134 fn from_value(v: Value) -> Option<Self> {
135 let Value::Object(obj) = v else {
136 return None;
137 };
138 let mut b = PaymentLinksResourceCustomFieldsBuilder::deser_default();
139 for (k, v) in obj {
140 match k.as_str() {
141 "dropdown" => b.dropdown = FromValueOpt::from_value(v),
142 "key" => b.key = FromValueOpt::from_value(v),
143 "label" => b.label = FromValueOpt::from_value(v),
144 "numeric" => b.numeric = FromValueOpt::from_value(v),
145 "optional" => b.optional = FromValueOpt::from_value(v),
146 "text" => b.text = FromValueOpt::from_value(v),
147 "type" => b.type_ = FromValueOpt::from_value(v),
148 _ => {}
149 }
150 }
151 b.take_out()
152 }
153 }
154};
155#[derive(Clone, Eq, PartialEq)]
157#[non_exhaustive]
158pub enum PaymentLinksResourceCustomFieldsType {
159 Dropdown,
160 Numeric,
161 Text,
162 Unknown(String),
164}
165impl PaymentLinksResourceCustomFieldsType {
166 pub fn as_str(&self) -> &str {
167 use PaymentLinksResourceCustomFieldsType::*;
168 match self {
169 Dropdown => "dropdown",
170 Numeric => "numeric",
171 Text => "text",
172 Unknown(v) => v,
173 }
174 }
175}
176
177impl std::str::FromStr for PaymentLinksResourceCustomFieldsType {
178 type Err = std::convert::Infallible;
179 fn from_str(s: &str) -> Result<Self, Self::Err> {
180 use PaymentLinksResourceCustomFieldsType::*;
181 match s {
182 "dropdown" => Ok(Dropdown),
183 "numeric" => Ok(Numeric),
184 "text" => Ok(Text),
185 v => {
186 tracing::warn!(
187 "Unknown value '{}' for enum '{}'",
188 v,
189 "PaymentLinksResourceCustomFieldsType"
190 );
191 Ok(Unknown(v.to_owned()))
192 }
193 }
194 }
195}
196impl std::fmt::Display for PaymentLinksResourceCustomFieldsType {
197 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
198 f.write_str(self.as_str())
199 }
200}
201
202impl std::fmt::Debug for PaymentLinksResourceCustomFieldsType {
203 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
204 f.write_str(self.as_str())
205 }
206}
207#[cfg(feature = "serialize")]
208impl serde::Serialize for PaymentLinksResourceCustomFieldsType {
209 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
210 where
211 S: serde::Serializer,
212 {
213 serializer.serialize_str(self.as_str())
214 }
215}
216impl miniserde::Deserialize for PaymentLinksResourceCustomFieldsType {
217 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
218 crate::Place::new(out)
219 }
220}
221
222impl miniserde::de::Visitor for crate::Place<PaymentLinksResourceCustomFieldsType> {
223 fn string(&mut self, s: &str) -> miniserde::Result<()> {
224 use std::str::FromStr;
225 self.out = Some(PaymentLinksResourceCustomFieldsType::from_str(s).expect("infallible"));
226 Ok(())
227 }
228}
229
230stripe_types::impl_from_val_with_from_str!(PaymentLinksResourceCustomFieldsType);
231#[cfg(feature = "deserialize")]
232impl<'de> serde::Deserialize<'de> for PaymentLinksResourceCustomFieldsType {
233 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
234 use std::str::FromStr;
235 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
236 Ok(Self::from_str(&s).expect("infallible"))
237 }
238}