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