Skip to main content

stripe_misc/
gelato_session_matching_options.rs

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