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