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                _ => <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, self.name) 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/// Strictness of the DOB matching policy to apply.
107#[derive(Copy, Clone, Eq, PartialEq)]
108pub enum GelatoSessionMatchingOptionsDob {
109    None,
110    Similar,
111}
112impl GelatoSessionMatchingOptionsDob {
113    pub fn as_str(self) -> &'static str {
114        use GelatoSessionMatchingOptionsDob::*;
115        match self {
116            None => "none",
117            Similar => "similar",
118        }
119    }
120}
121
122impl std::str::FromStr for GelatoSessionMatchingOptionsDob {
123    type Err = stripe_types::StripeParseError;
124    fn from_str(s: &str) -> Result<Self, Self::Err> {
125        use GelatoSessionMatchingOptionsDob::*;
126        match s {
127            "none" => Ok(None),
128            "similar" => Ok(Similar),
129            _ => Err(stripe_types::StripeParseError),
130        }
131    }
132}
133impl std::fmt::Display for GelatoSessionMatchingOptionsDob {
134    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
135        f.write_str(self.as_str())
136    }
137}
138
139impl std::fmt::Debug for GelatoSessionMatchingOptionsDob {
140    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
141        f.write_str(self.as_str())
142    }
143}
144#[cfg(feature = "serialize")]
145impl serde::Serialize for GelatoSessionMatchingOptionsDob {
146    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
147    where
148        S: serde::Serializer,
149    {
150        serializer.serialize_str(self.as_str())
151    }
152}
153impl miniserde::Deserialize for GelatoSessionMatchingOptionsDob {
154    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
155        crate::Place::new(out)
156    }
157}
158
159impl miniserde::de::Visitor for crate::Place<GelatoSessionMatchingOptionsDob> {
160    fn string(&mut self, s: &str) -> miniserde::Result<()> {
161        use std::str::FromStr;
162        self.out =
163            Some(GelatoSessionMatchingOptionsDob::from_str(s).map_err(|_| miniserde::Error)?);
164        Ok(())
165    }
166}
167
168stripe_types::impl_from_val_with_from_str!(GelatoSessionMatchingOptionsDob);
169#[cfg(feature = "deserialize")]
170impl<'de> serde::Deserialize<'de> for GelatoSessionMatchingOptionsDob {
171    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
172        use std::str::FromStr;
173        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
174        Self::from_str(&s).map_err(|_| {
175            serde::de::Error::custom("Unknown value for GelatoSessionMatchingOptionsDob")
176        })
177    }
178}
179/// Strictness of the name matching policy to apply.
180#[derive(Copy, Clone, Eq, PartialEq)]
181pub enum GelatoSessionMatchingOptionsName {
182    None,
183    Similar,
184}
185impl GelatoSessionMatchingOptionsName {
186    pub fn as_str(self) -> &'static str {
187        use GelatoSessionMatchingOptionsName::*;
188        match self {
189            None => "none",
190            Similar => "similar",
191        }
192    }
193}
194
195impl std::str::FromStr for GelatoSessionMatchingOptionsName {
196    type Err = stripe_types::StripeParseError;
197    fn from_str(s: &str) -> Result<Self, Self::Err> {
198        use GelatoSessionMatchingOptionsName::*;
199        match s {
200            "none" => Ok(None),
201            "similar" => Ok(Similar),
202            _ => Err(stripe_types::StripeParseError),
203        }
204    }
205}
206impl std::fmt::Display for GelatoSessionMatchingOptionsName {
207    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
208        f.write_str(self.as_str())
209    }
210}
211
212impl std::fmt::Debug for GelatoSessionMatchingOptionsName {
213    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
214        f.write_str(self.as_str())
215    }
216}
217#[cfg(feature = "serialize")]
218impl serde::Serialize for GelatoSessionMatchingOptionsName {
219    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
220    where
221        S: serde::Serializer,
222    {
223        serializer.serialize_str(self.as_str())
224    }
225}
226impl miniserde::Deserialize for GelatoSessionMatchingOptionsName {
227    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
228        crate::Place::new(out)
229    }
230}
231
232impl miniserde::de::Visitor for crate::Place<GelatoSessionMatchingOptionsName> {
233    fn string(&mut self, s: &str) -> miniserde::Result<()> {
234        use std::str::FromStr;
235        self.out =
236            Some(GelatoSessionMatchingOptionsName::from_str(s).map_err(|_| miniserde::Error)?);
237        Ok(())
238    }
239}
240
241stripe_types::impl_from_val_with_from_str!(GelatoSessionMatchingOptionsName);
242#[cfg(feature = "deserialize")]
243impl<'de> serde::Deserialize<'de> for GelatoSessionMatchingOptionsName {
244    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
245        use std::str::FromStr;
246        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
247        Self::from_str(&s).map_err(|_| {
248            serde::de::Error::custom("Unknown value for GelatoSessionMatchingOptionsName")
249        })
250    }
251}