stripe_misc/
gelato_document_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 GelatoDocumentReportError {
6 pub code: Option<GelatoDocumentReportErrorCode>,
8 pub reason: Option<String>,
11}
12#[cfg(feature = "redact-generated-debug")]
13impl std::fmt::Debug for GelatoDocumentReportError {
14 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
15 f.debug_struct("GelatoDocumentReportError").finish_non_exhaustive()
16 }
17}
18#[doc(hidden)]
19pub struct GelatoDocumentReportErrorBuilder {
20 code: Option<Option<GelatoDocumentReportErrorCode>>,
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 GelatoDocumentReportError {
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<GelatoDocumentReportError>,
48 builder: GelatoDocumentReportErrorBuilder,
49 }
50
51 impl Visitor for Place<GelatoDocumentReportError> {
52 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
53 Ok(Box::new(Builder {
54 out: &mut self.out,
55 builder: GelatoDocumentReportErrorBuilder::deser_default(),
56 }))
57 }
58 }
59
60 impl MapBuilder for GelatoDocumentReportErrorBuilder {
61 type Out = GelatoDocumentReportError;
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 GelatoDocumentReportError {
94 type Builder = GelatoDocumentReportErrorBuilder;
95 }
96
97 impl FromValueOpt for GelatoDocumentReportError {
98 fn from_value(v: Value) -> Option<Self> {
99 let Value::Object(obj) = v else {
100 return None;
101 };
102 let mut b = GelatoDocumentReportErrorBuilder::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 GelatoDocumentReportErrorCode {
118 DocumentExpired,
119 DocumentTypeNotSupported,
120 DocumentUnverifiedOther,
121 Unknown(String),
123}
124impl GelatoDocumentReportErrorCode {
125 pub fn as_str(&self) -> &str {
126 use GelatoDocumentReportErrorCode::*;
127 match self {
128 DocumentExpired => "document_expired",
129 DocumentTypeNotSupported => "document_type_not_supported",
130 DocumentUnverifiedOther => "document_unverified_other",
131 Unknown(v) => v,
132 }
133 }
134}
135
136impl std::str::FromStr for GelatoDocumentReportErrorCode {
137 type Err = std::convert::Infallible;
138 fn from_str(s: &str) -> Result<Self, Self::Err> {
139 use GelatoDocumentReportErrorCode::*;
140 match s {
141 "document_expired" => Ok(DocumentExpired),
142 "document_type_not_supported" => Ok(DocumentTypeNotSupported),
143 "document_unverified_other" => Ok(DocumentUnverifiedOther),
144 v => {
145 tracing::warn!(
146 "Unknown value '{}' for enum '{}'",
147 v,
148 "GelatoDocumentReportErrorCode"
149 );
150 Ok(Unknown(v.to_owned()))
151 }
152 }
153 }
154}
155impl std::fmt::Display for GelatoDocumentReportErrorCode {
156 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
157 f.write_str(self.as_str())
158 }
159}
160
161#[cfg(not(feature = "redact-generated-debug"))]
162impl std::fmt::Debug for GelatoDocumentReportErrorCode {
163 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
164 f.write_str(self.as_str())
165 }
166}
167#[cfg(feature = "redact-generated-debug")]
168impl std::fmt::Debug for GelatoDocumentReportErrorCode {
169 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
170 f.debug_struct(stringify!(GelatoDocumentReportErrorCode)).finish_non_exhaustive()
171 }
172}
173#[cfg(feature = "serialize")]
174impl serde::Serialize for GelatoDocumentReportErrorCode {
175 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
176 where
177 S: serde::Serializer,
178 {
179 serializer.serialize_str(self.as_str())
180 }
181}
182impl miniserde::Deserialize for GelatoDocumentReportErrorCode {
183 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
184 crate::Place::new(out)
185 }
186}
187
188impl miniserde::de::Visitor for crate::Place<GelatoDocumentReportErrorCode> {
189 fn string(&mut self, s: &str) -> miniserde::Result<()> {
190 use std::str::FromStr;
191 self.out = Some(GelatoDocumentReportErrorCode::from_str(s).expect("infallible"));
192 Ok(())
193 }
194}
195
196stripe_types::impl_from_val_with_from_str!(GelatoDocumentReportErrorCode);
197#[cfg(feature = "deserialize")]
198impl<'de> serde::Deserialize<'de> for GelatoDocumentReportErrorCode {
199 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
200 use std::str::FromStr;
201 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
202 Ok(Self::from_str(&s).expect("infallible"))
203 }
204}