stripe_shared/
person_ethnicity_details.rs1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PersonEthnicityDetails {
5 pub ethnicity: Option<Vec<PersonEthnicityDetailsEthnicity>>,
7 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#[derive(Clone, Eq, PartialEq)]
110#[non_exhaustive]
111pub enum PersonEthnicityDetailsEthnicity {
112 Cuban,
113 HispanicOrLatino,
114 Mexican,
115 NotHispanicOrLatino,
116 OtherHispanicOrLatino,
117 PreferNotToAnswer,
118 PuertoRican,
119 Unknown(String),
121}
122impl PersonEthnicityDetailsEthnicity {
123 pub fn as_str(&self) -> &str {
124 use PersonEthnicityDetailsEthnicity::*;
125 match self {
126 Cuban => "cuban",
127 HispanicOrLatino => "hispanic_or_latino",
128 Mexican => "mexican",
129 NotHispanicOrLatino => "not_hispanic_or_latino",
130 OtherHispanicOrLatino => "other_hispanic_or_latino",
131 PreferNotToAnswer => "prefer_not_to_answer",
132 PuertoRican => "puerto_rican",
133 Unknown(v) => v,
134 }
135 }
136}
137
138impl std::str::FromStr for PersonEthnicityDetailsEthnicity {
139 type Err = std::convert::Infallible;
140 fn from_str(s: &str) -> Result<Self, Self::Err> {
141 use PersonEthnicityDetailsEthnicity::*;
142 match s {
143 "cuban" => Ok(Cuban),
144 "hispanic_or_latino" => Ok(HispanicOrLatino),
145 "mexican" => Ok(Mexican),
146 "not_hispanic_or_latino" => Ok(NotHispanicOrLatino),
147 "other_hispanic_or_latino" => Ok(OtherHispanicOrLatino),
148 "prefer_not_to_answer" => Ok(PreferNotToAnswer),
149 "puerto_rican" => Ok(PuertoRican),
150 v => {
151 tracing::warn!(
152 "Unknown value '{}' for enum '{}'",
153 v,
154 "PersonEthnicityDetailsEthnicity"
155 );
156 Ok(Unknown(v.to_owned()))
157 }
158 }
159 }
160}
161impl std::fmt::Display for PersonEthnicityDetailsEthnicity {
162 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
163 f.write_str(self.as_str())
164 }
165}
166
167impl std::fmt::Debug for PersonEthnicityDetailsEthnicity {
168 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
169 f.write_str(self.as_str())
170 }
171}
172#[cfg(feature = "serialize")]
173impl serde::Serialize for PersonEthnicityDetailsEthnicity {
174 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
175 where
176 S: serde::Serializer,
177 {
178 serializer.serialize_str(self.as_str())
179 }
180}
181impl miniserde::Deserialize for PersonEthnicityDetailsEthnicity {
182 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
183 crate::Place::new(out)
184 }
185}
186
187impl miniserde::de::Visitor for crate::Place<PersonEthnicityDetailsEthnicity> {
188 fn string(&mut self, s: &str) -> miniserde::Result<()> {
189 use std::str::FromStr;
190 self.out = Some(PersonEthnicityDetailsEthnicity::from_str(s).expect("infallible"));
191 Ok(())
192 }
193}
194
195stripe_types::impl_from_val_with_from_str!(PersonEthnicityDetailsEthnicity);
196#[cfg(feature = "deserialize")]
197impl<'de> serde::Deserialize<'de> for PersonEthnicityDetailsEthnicity {
198 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
199 use std::str::FromStr;
200 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
201 Ok(Self::from_str(&s).expect("infallible"))
202 }
203}