stripe_shared/
person_ethnicity_details.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PersonEthnicityDetails {
5    /// The persons ethnicity
6    pub ethnicity: Option<Vec<PersonEthnicityDetailsEthnicity>>,
7    /// Please specify your origin, when other is selected.
8    pub ethnicity_other: Option<String>,
9}
10#[doc(hidden)]
11pub struct PersonEthnicityDetailsBuilder {
12    ethnicity: Option<Option<Vec<PersonEthnicityDetailsEthnicity>>>,
13    ethnicity_other: Option<Option<String>>,
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 PersonEthnicityDetails {
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<PersonEthnicityDetails>,
40        builder: PersonEthnicityDetailsBuilder,
41    }
42
43    impl Visitor for Place<PersonEthnicityDetails> {
44        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
45            Ok(Box::new(Builder {
46                out: &mut self.out,
47                builder: PersonEthnicityDetailsBuilder::deser_default(),
48            }))
49        }
50    }
51
52    impl MapBuilder for PersonEthnicityDetailsBuilder {
53        type Out = PersonEthnicityDetails;
54        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
55            Ok(match k {
56                "ethnicity" => Deserialize::begin(&mut self.ethnicity),
57                "ethnicity_other" => Deserialize::begin(&mut self.ethnicity_other),
58                _ => <dyn Visitor>::ignore(),
59            })
60        }
61
62        fn deser_default() -> Self {
63            Self { ethnicity: Deserialize::default(), ethnicity_other: Deserialize::default() }
64        }
65
66        fn take_out(&mut self) -> Option<Self::Out> {
67            let (Some(ethnicity), Some(ethnicity_other)) =
68                (self.ethnicity.take(), self.ethnicity_other.take())
69            else {
70                return None;
71            };
72            Some(Self::Out { ethnicity, ethnicity_other })
73        }
74    }
75
76    impl Map for Builder<'_> {
77        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
78            self.builder.key(k)
79        }
80
81        fn finish(&mut self) -> Result<()> {
82            *self.out = self.builder.take_out();
83            Ok(())
84        }
85    }
86
87    impl ObjectDeser for PersonEthnicityDetails {
88        type Builder = PersonEthnicityDetailsBuilder;
89    }
90
91    impl FromValueOpt for PersonEthnicityDetails {
92        fn from_value(v: Value) -> Option<Self> {
93            let Value::Object(obj) = v else {
94                return None;
95            };
96            let mut b = PersonEthnicityDetailsBuilder::deser_default();
97            for (k, v) in obj {
98                match k.as_str() {
99                    "ethnicity" => b.ethnicity = FromValueOpt::from_value(v),
100                    "ethnicity_other" => b.ethnicity_other = FromValueOpt::from_value(v),
101                    _ => {}
102                }
103            }
104            b.take_out()
105        }
106    }
107};
108/// The persons ethnicity
109#[derive(Copy, Clone, Eq, PartialEq)]
110pub enum PersonEthnicityDetailsEthnicity {
111    Cuban,
112    HispanicOrLatino,
113    Mexican,
114    NotHispanicOrLatino,
115    OtherHispanicOrLatino,
116    PreferNotToAnswer,
117    PuertoRican,
118}
119impl PersonEthnicityDetailsEthnicity {
120    pub fn as_str(self) -> &'static str {
121        use PersonEthnicityDetailsEthnicity::*;
122        match self {
123            Cuban => "cuban",
124            HispanicOrLatino => "hispanic_or_latino",
125            Mexican => "mexican",
126            NotHispanicOrLatino => "not_hispanic_or_latino",
127            OtherHispanicOrLatino => "other_hispanic_or_latino",
128            PreferNotToAnswer => "prefer_not_to_answer",
129            PuertoRican => "puerto_rican",
130        }
131    }
132}
133
134impl std::str::FromStr for PersonEthnicityDetailsEthnicity {
135    type Err = stripe_types::StripeParseError;
136    fn from_str(s: &str) -> Result<Self, Self::Err> {
137        use PersonEthnicityDetailsEthnicity::*;
138        match s {
139            "cuban" => Ok(Cuban),
140            "hispanic_or_latino" => Ok(HispanicOrLatino),
141            "mexican" => Ok(Mexican),
142            "not_hispanic_or_latino" => Ok(NotHispanicOrLatino),
143            "other_hispanic_or_latino" => Ok(OtherHispanicOrLatino),
144            "prefer_not_to_answer" => Ok(PreferNotToAnswer),
145            "puerto_rican" => Ok(PuertoRican),
146            _ => Err(stripe_types::StripeParseError),
147        }
148    }
149}
150impl std::fmt::Display for PersonEthnicityDetailsEthnicity {
151    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
152        f.write_str(self.as_str())
153    }
154}
155
156impl std::fmt::Debug for PersonEthnicityDetailsEthnicity {
157    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
158        f.write_str(self.as_str())
159    }
160}
161#[cfg(feature = "serialize")]
162impl serde::Serialize for PersonEthnicityDetailsEthnicity {
163    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
164    where
165        S: serde::Serializer,
166    {
167        serializer.serialize_str(self.as_str())
168    }
169}
170impl miniserde::Deserialize for PersonEthnicityDetailsEthnicity {
171    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
172        crate::Place::new(out)
173    }
174}
175
176impl miniserde::de::Visitor for crate::Place<PersonEthnicityDetailsEthnicity> {
177    fn string(&mut self, s: &str) -> miniserde::Result<()> {
178        use std::str::FromStr;
179        self.out =
180            Some(PersonEthnicityDetailsEthnicity::from_str(s).map_err(|_| miniserde::Error)?);
181        Ok(())
182    }
183}
184
185stripe_types::impl_from_val_with_from_str!(PersonEthnicityDetailsEthnicity);
186#[cfg(feature = "deserialize")]
187impl<'de> serde::Deserialize<'de> for PersonEthnicityDetailsEthnicity {
188    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
189        use std::str::FromStr;
190        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
191        Self::from_str(&s).map_err(|_| {
192            serde::de::Error::custom("Unknown value for PersonEthnicityDetailsEthnicity")
193        })
194    }
195}