stripe_misc/
gelato_phone_report.rs1#[derive(Clone, Debug)]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct GelatoPhoneReport {
6 pub error: Option<stripe_misc::GelatoPhoneReportError>,
8 pub phone: Option<String>,
10 pub status: GelatoPhoneReportStatus,
12}
13#[doc(hidden)]
14pub struct GelatoPhoneReportBuilder {
15 error: Option<Option<stripe_misc::GelatoPhoneReportError>>,
16 phone: Option<Option<String>>,
17 status: Option<GelatoPhoneReportStatus>,
18}
19
20#[allow(
21 unused_variables,
22 irrefutable_let_patterns,
23 clippy::let_unit_value,
24 clippy::match_single_binding,
25 clippy::single_match
26)]
27const _: () = {
28 use miniserde::de::{Map, Visitor};
29 use miniserde::json::Value;
30 use miniserde::{Deserialize, Result, make_place};
31 use stripe_types::miniserde_helpers::FromValueOpt;
32 use stripe_types::{MapBuilder, ObjectDeser};
33
34 make_place!(Place);
35
36 impl Deserialize for GelatoPhoneReport {
37 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
38 Place::new(out)
39 }
40 }
41
42 struct Builder<'a> {
43 out: &'a mut Option<GelatoPhoneReport>,
44 builder: GelatoPhoneReportBuilder,
45 }
46
47 impl Visitor for Place<GelatoPhoneReport> {
48 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
49 Ok(Box::new(Builder {
50 out: &mut self.out,
51 builder: GelatoPhoneReportBuilder::deser_default(),
52 }))
53 }
54 }
55
56 impl MapBuilder for GelatoPhoneReportBuilder {
57 type Out = GelatoPhoneReport;
58 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
59 Ok(match k {
60 "error" => Deserialize::begin(&mut self.error),
61 "phone" => Deserialize::begin(&mut self.phone),
62 "status" => Deserialize::begin(&mut self.status),
63 _ => <dyn Visitor>::ignore(),
64 })
65 }
66
67 fn deser_default() -> Self {
68 Self {
69 error: Deserialize::default(),
70 phone: Deserialize::default(),
71 status: Deserialize::default(),
72 }
73 }
74
75 fn take_out(&mut self) -> Option<Self::Out> {
76 let (Some(error), Some(phone), Some(status)) =
77 (self.error.take(), self.phone.take(), self.status.take())
78 else {
79 return None;
80 };
81 Some(Self::Out { error, phone, status })
82 }
83 }
84
85 impl Map for Builder<'_> {
86 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
87 self.builder.key(k)
88 }
89
90 fn finish(&mut self) -> Result<()> {
91 *self.out = self.builder.take_out();
92 Ok(())
93 }
94 }
95
96 impl ObjectDeser for GelatoPhoneReport {
97 type Builder = GelatoPhoneReportBuilder;
98 }
99
100 impl FromValueOpt for GelatoPhoneReport {
101 fn from_value(v: Value) -> Option<Self> {
102 let Value::Object(obj) = v else {
103 return None;
104 };
105 let mut b = GelatoPhoneReportBuilder::deser_default();
106 for (k, v) in obj {
107 match k.as_str() {
108 "error" => b.error = FromValueOpt::from_value(v),
109 "phone" => b.phone = FromValueOpt::from_value(v),
110 "status" => b.status = FromValueOpt::from_value(v),
111 _ => {}
112 }
113 }
114 b.take_out()
115 }
116 }
117};
118#[derive(Clone, Eq, PartialEq)]
120#[non_exhaustive]
121pub enum GelatoPhoneReportStatus {
122 Unverified,
123 Verified,
124 Unknown(String),
126}
127impl GelatoPhoneReportStatus {
128 pub fn as_str(&self) -> &str {
129 use GelatoPhoneReportStatus::*;
130 match self {
131 Unverified => "unverified",
132 Verified => "verified",
133 Unknown(v) => v,
134 }
135 }
136}
137
138impl std::str::FromStr for GelatoPhoneReportStatus {
139 type Err = std::convert::Infallible;
140 fn from_str(s: &str) -> Result<Self, Self::Err> {
141 use GelatoPhoneReportStatus::*;
142 match s {
143 "unverified" => Ok(Unverified),
144 "verified" => Ok(Verified),
145 v => {
146 tracing::warn!("Unknown value '{}' for enum '{}'", v, "GelatoPhoneReportStatus");
147 Ok(Unknown(v.to_owned()))
148 }
149 }
150 }
151}
152impl std::fmt::Display for GelatoPhoneReportStatus {
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 GelatoPhoneReportStatus {
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 GelatoPhoneReportStatus {
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 GelatoPhoneReportStatus {
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<GelatoPhoneReportStatus> {
179 fn string(&mut self, s: &str) -> miniserde::Result<()> {
180 use std::str::FromStr;
181 self.out = Some(GelatoPhoneReportStatus::from_str(s).expect("infallible"));
182 Ok(())
183 }
184}
185
186stripe_types::impl_from_val_with_from_str!(GelatoPhoneReportStatus);
187#[cfg(feature = "deserialize")]
188impl<'de> serde::Deserialize<'de> for GelatoPhoneReportStatus {
189 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
190 use std::str::FromStr;
191 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
192 Ok(Self::from_str(&s).expect("infallible"))
193 }
194}