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