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