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