stripe_misc/
gelato_session_matching_options.rs

1#[derive(Copy, Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct GelatoSessionMatchingOptions {
5    /// Strictness of the DOB matching policy to apply.
6    pub dob: Option<GelatoSessionMatchingOptionsDob>,
7    /// Strictness of the name matching policy to apply.
8    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
59                _ => <dyn Visitor>::ignore(),
60            })
61        }
62
63        fn deser_default() -> Self {
64            Self { dob: Deserialize::default(), name: Deserialize::default() }
65        }
66
67        fn take_out(&mut self) -> Option<Self::Out> {
68            let (Some(dob), Some(name)) = (self.dob, self.name) else {
69                return None;
70            };
71            Some(Self::Out { dob, name })
72        }
73    }
74
75    impl Map for Builder<'_> {
76        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
77            self.builder.key(k)
78        }
79
80        fn finish(&mut self) -> Result<()> {
81            *self.out = self.builder.take_out();
82            Ok(())
83        }
84    }
85
86    impl ObjectDeser for GelatoSessionMatchingOptions {
87        type Builder = GelatoSessionMatchingOptionsBuilder;
88    }
89
90    impl FromValueOpt for GelatoSessionMatchingOptions {
91        fn from_value(v: Value) -> Option<Self> {
92            let Value::Object(obj) = v else {
93                return None;
94            };
95            let mut b = GelatoSessionMatchingOptionsBuilder::deser_default();
96            for (k, v) in obj {
97                match k.as_str() {
98                    "dob" => b.dob = FromValueOpt::from_value(v),
99                    "name" => b.name = FromValueOpt::from_value(v),
100
101                    _ => {}
102                }
103            }
104            b.take_out()
105        }
106    }
107};
108/// Strictness of the DOB matching policy to apply.
109#[derive(Copy, Clone, Eq, PartialEq)]
110pub enum GelatoSessionMatchingOptionsDob {
111    None,
112    Similar,
113}
114impl GelatoSessionMatchingOptionsDob {
115    pub fn as_str(self) -> &'static str {
116        use GelatoSessionMatchingOptionsDob::*;
117        match self {
118            None => "none",
119            Similar => "similar",
120        }
121    }
122}
123
124impl std::str::FromStr for GelatoSessionMatchingOptionsDob {
125    type Err = stripe_types::StripeParseError;
126    fn from_str(s: &str) -> Result<Self, Self::Err> {
127        use GelatoSessionMatchingOptionsDob::*;
128        match s {
129            "none" => Ok(None),
130            "similar" => Ok(Similar),
131            _ => Err(stripe_types::StripeParseError),
132        }
133    }
134}
135impl std::fmt::Display for GelatoSessionMatchingOptionsDob {
136    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
137        f.write_str(self.as_str())
138    }
139}
140
141impl std::fmt::Debug for GelatoSessionMatchingOptionsDob {
142    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
143        f.write_str(self.as_str())
144    }
145}
146#[cfg(feature = "serialize")]
147impl serde::Serialize for GelatoSessionMatchingOptionsDob {
148    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
149    where
150        S: serde::Serializer,
151    {
152        serializer.serialize_str(self.as_str())
153    }
154}
155impl miniserde::Deserialize for GelatoSessionMatchingOptionsDob {
156    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
157        crate::Place::new(out)
158    }
159}
160
161impl miniserde::de::Visitor for crate::Place<GelatoSessionMatchingOptionsDob> {
162    fn string(&mut self, s: &str) -> miniserde::Result<()> {
163        use std::str::FromStr;
164        self.out =
165            Some(GelatoSessionMatchingOptionsDob::from_str(s).map_err(|_| miniserde::Error)?);
166        Ok(())
167    }
168}
169
170stripe_types::impl_from_val_with_from_str!(GelatoSessionMatchingOptionsDob);
171#[cfg(feature = "deserialize")]
172impl<'de> serde::Deserialize<'de> for GelatoSessionMatchingOptionsDob {
173    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
174        use std::str::FromStr;
175        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
176        Self::from_str(&s).map_err(|_| {
177            serde::de::Error::custom("Unknown value for GelatoSessionMatchingOptionsDob")
178        })
179    }
180}
181/// Strictness of the name matching policy to apply.
182#[derive(Copy, Clone, Eq, PartialEq)]
183pub enum GelatoSessionMatchingOptionsName {
184    None,
185    Similar,
186}
187impl GelatoSessionMatchingOptionsName {
188    pub fn as_str(self) -> &'static str {
189        use GelatoSessionMatchingOptionsName::*;
190        match self {
191            None => "none",
192            Similar => "similar",
193        }
194    }
195}
196
197impl std::str::FromStr for GelatoSessionMatchingOptionsName {
198    type Err = stripe_types::StripeParseError;
199    fn from_str(s: &str) -> Result<Self, Self::Err> {
200        use GelatoSessionMatchingOptionsName::*;
201        match s {
202            "none" => Ok(None),
203            "similar" => Ok(Similar),
204            _ => Err(stripe_types::StripeParseError),
205        }
206    }
207}
208impl std::fmt::Display for GelatoSessionMatchingOptionsName {
209    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
210        f.write_str(self.as_str())
211    }
212}
213
214impl std::fmt::Debug for GelatoSessionMatchingOptionsName {
215    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
216        f.write_str(self.as_str())
217    }
218}
219#[cfg(feature = "serialize")]
220impl serde::Serialize for GelatoSessionMatchingOptionsName {
221    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
222    where
223        S: serde::Serializer,
224    {
225        serializer.serialize_str(self.as_str())
226    }
227}
228impl miniserde::Deserialize for GelatoSessionMatchingOptionsName {
229    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
230        crate::Place::new(out)
231    }
232}
233
234impl miniserde::de::Visitor for crate::Place<GelatoSessionMatchingOptionsName> {
235    fn string(&mut self, s: &str) -> miniserde::Result<()> {
236        use std::str::FromStr;
237        self.out =
238            Some(GelatoSessionMatchingOptionsName::from_str(s).map_err(|_| miniserde::Error)?);
239        Ok(())
240    }
241}
242
243stripe_types::impl_from_val_with_from_str!(GelatoSessionMatchingOptionsName);
244#[cfg(feature = "deserialize")]
245impl<'de> serde::Deserialize<'de> for GelatoSessionMatchingOptionsName {
246    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
247        use std::str::FromStr;
248        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
249        Self::from_str(&s).map_err(|_| {
250            serde::de::Error::custom("Unknown value for GelatoSessionMatchingOptionsName")
251        })
252    }
253}