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