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