stripe_misc/
gelato_email_report_error.rs1#[derive(Clone, Eq, PartialEq)]
2#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct GelatoEmailReportError {
6 pub code: Option<GelatoEmailReportErrorCode>,
8 pub reason: Option<String>,
11}
12#[cfg(feature = "redact-generated-debug")]
13impl std::fmt::Debug for GelatoEmailReportError {
14 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
15 f.debug_struct("GelatoEmailReportError").finish_non_exhaustive()
16 }
17}
18#[doc(hidden)]
19pub struct GelatoEmailReportErrorBuilder {
20 code: Option<Option<GelatoEmailReportErrorCode>>,
21 reason: Option<Option<String>>,
22}
23
24#[allow(
25 unused_variables,
26 irrefutable_let_patterns,
27 clippy::let_unit_value,
28 clippy::match_single_binding,
29 clippy::single_match
30)]
31const _: () = {
32 use miniserde::de::{Map, Visitor};
33 use miniserde::json::Value;
34 use miniserde::{Deserialize, Result, make_place};
35 use stripe_types::miniserde_helpers::FromValueOpt;
36 use stripe_types::{MapBuilder, ObjectDeser};
37
38 make_place!(Place);
39
40 impl Deserialize for GelatoEmailReportError {
41 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
42 Place::new(out)
43 }
44 }
45
46 struct Builder<'a> {
47 out: &'a mut Option<GelatoEmailReportError>,
48 builder: GelatoEmailReportErrorBuilder,
49 }
50
51 impl Visitor for Place<GelatoEmailReportError> {
52 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
53 Ok(Box::new(Builder {
54 out: &mut self.out,
55 builder: GelatoEmailReportErrorBuilder::deser_default(),
56 }))
57 }
58 }
59
60 impl MapBuilder for GelatoEmailReportErrorBuilder {
61 type Out = GelatoEmailReportError;
62 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
63 Ok(match k {
64 "code" => Deserialize::begin(&mut self.code),
65 "reason" => Deserialize::begin(&mut self.reason),
66 _ => <dyn Visitor>::ignore(),
67 })
68 }
69
70 fn deser_default() -> Self {
71 Self { code: Some(None), reason: Some(None) }
72 }
73
74 fn take_out(&mut self) -> Option<Self::Out> {
75 let (Some(code), Some(reason)) = (self.code.take(), self.reason.take()) else {
76 return None;
77 };
78 Some(Self::Out { code, reason })
79 }
80 }
81
82 impl Map for Builder<'_> {
83 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
84 self.builder.key(k)
85 }
86
87 fn finish(&mut self) -> Result<()> {
88 *self.out = self.builder.take_out();
89 Ok(())
90 }
91 }
92
93 impl ObjectDeser for GelatoEmailReportError {
94 type Builder = GelatoEmailReportErrorBuilder;
95 }
96
97 impl FromValueOpt for GelatoEmailReportError {
98 fn from_value(v: Value) -> Option<Self> {
99 let Value::Object(obj) = v else {
100 return None;
101 };
102 let mut b = GelatoEmailReportErrorBuilder::deser_default();
103 for (k, v) in obj {
104 match k.as_str() {
105 "code" => b.code = FromValueOpt::from_value(v),
106 "reason" => b.reason = FromValueOpt::from_value(v),
107 _ => {}
108 }
109 }
110 b.take_out()
111 }
112 }
113};
114#[derive(Clone, Eq, PartialEq)]
116#[non_exhaustive]
117pub enum GelatoEmailReportErrorCode {
118 EmailUnverifiedOther,
119 EmailVerificationDeclined,
120 Unknown(String),
122}
123impl GelatoEmailReportErrorCode {
124 pub fn as_str(&self) -> &str {
125 use GelatoEmailReportErrorCode::*;
126 match self {
127 EmailUnverifiedOther => "email_unverified_other",
128 EmailVerificationDeclined => "email_verification_declined",
129 Unknown(v) => v,
130 }
131 }
132}
133
134impl std::str::FromStr for GelatoEmailReportErrorCode {
135 type Err = std::convert::Infallible;
136 fn from_str(s: &str) -> Result<Self, Self::Err> {
137 use GelatoEmailReportErrorCode::*;
138 match s {
139 "email_unverified_other" => Ok(EmailUnverifiedOther),
140 "email_verification_declined" => Ok(EmailVerificationDeclined),
141 v => {
142 tracing::warn!("Unknown value '{}' for enum '{}'", v, "GelatoEmailReportErrorCode");
143 Ok(Unknown(v.to_owned()))
144 }
145 }
146 }
147}
148impl std::fmt::Display for GelatoEmailReportErrorCode {
149 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
150 f.write_str(self.as_str())
151 }
152}
153
154#[cfg(not(feature = "redact-generated-debug"))]
155impl std::fmt::Debug for GelatoEmailReportErrorCode {
156 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
157 f.write_str(self.as_str())
158 }
159}
160#[cfg(feature = "redact-generated-debug")]
161impl std::fmt::Debug for GelatoEmailReportErrorCode {
162 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
163 f.debug_struct(stringify!(GelatoEmailReportErrorCode)).finish_non_exhaustive()
164 }
165}
166#[cfg(feature = "serialize")]
167impl serde::Serialize for GelatoEmailReportErrorCode {
168 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
169 where
170 S: serde::Serializer,
171 {
172 serializer.serialize_str(self.as_str())
173 }
174}
175impl miniserde::Deserialize for GelatoEmailReportErrorCode {
176 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
177 crate::Place::new(out)
178 }
179}
180
181impl miniserde::de::Visitor for crate::Place<GelatoEmailReportErrorCode> {
182 fn string(&mut self, s: &str) -> miniserde::Result<()> {
183 use std::str::FromStr;
184 self.out = Some(GelatoEmailReportErrorCode::from_str(s).expect("infallible"));
185 Ok(())
186 }
187}
188
189stripe_types::impl_from_val_with_from_str!(GelatoEmailReportErrorCode);
190#[cfg(feature = "deserialize")]
191impl<'de> serde::Deserialize<'de> for GelatoEmailReportErrorCode {
192 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
193 use std::str::FromStr;
194 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
195 Ok(Self::from_str(&s).expect("infallible"))
196 }
197}