stripe_shared/
billing_bill_resource_invoicing_parents_invoice_parent.rs1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct BillingBillResourceInvoicingParentsInvoiceParent {
5 pub quote_details: Option<stripe_shared::BillingBillResourceInvoicingParentsInvoiceQuoteParent>,
7 pub subscription_details:
9 Option<stripe_shared::BillingBillResourceInvoicingParentsInvoiceSubscriptionParent>,
10 #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
12 pub type_: BillingBillResourceInvoicingParentsInvoiceParentType,
13}
14#[doc(hidden)]
15pub struct BillingBillResourceInvoicingParentsInvoiceParentBuilder {
16 quote_details:
17 Option<Option<stripe_shared::BillingBillResourceInvoicingParentsInvoiceQuoteParent>>,
18 subscription_details:
19 Option<Option<stripe_shared::BillingBillResourceInvoicingParentsInvoiceSubscriptionParent>>,
20 type_: Option<BillingBillResourceInvoicingParentsInvoiceParentType>,
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 BillingBillResourceInvoicingParentsInvoiceParent {
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<BillingBillResourceInvoicingParentsInvoiceParent>,
47 builder: BillingBillResourceInvoicingParentsInvoiceParentBuilder,
48 }
49
50 impl Visitor for Place<BillingBillResourceInvoicingParentsInvoiceParent> {
51 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
52 Ok(Box::new(Builder {
53 out: &mut self.out,
54 builder: BillingBillResourceInvoicingParentsInvoiceParentBuilder::deser_default(),
55 }))
56 }
57 }
58
59 impl MapBuilder for BillingBillResourceInvoicingParentsInvoiceParentBuilder {
60 type Out = BillingBillResourceInvoicingParentsInvoiceParent;
61 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
62 Ok(match k {
63 "quote_details" => Deserialize::begin(&mut self.quote_details),
64 "subscription_details" => Deserialize::begin(&mut self.subscription_details),
65 "type" => Deserialize::begin(&mut self.type_),
66 _ => <dyn Visitor>::ignore(),
67 })
68 }
69
70 fn deser_default() -> Self {
71 Self {
72 quote_details: Deserialize::default(),
73 subscription_details: Deserialize::default(),
74 type_: Deserialize::default(),
75 }
76 }
77
78 fn take_out(&mut self) -> Option<Self::Out> {
79 let (Some(quote_details), Some(subscription_details), Some(type_)) =
80 (self.quote_details.take(), self.subscription_details.take(), self.type_)
81 else {
82 return None;
83 };
84 Some(Self::Out { quote_details, subscription_details, type_ })
85 }
86 }
87
88 impl Map for Builder<'_> {
89 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
90 self.builder.key(k)
91 }
92
93 fn finish(&mut self) -> Result<()> {
94 *self.out = self.builder.take_out();
95 Ok(())
96 }
97 }
98
99 impl ObjectDeser for BillingBillResourceInvoicingParentsInvoiceParent {
100 type Builder = BillingBillResourceInvoicingParentsInvoiceParentBuilder;
101 }
102
103 impl FromValueOpt for BillingBillResourceInvoicingParentsInvoiceParent {
104 fn from_value(v: Value) -> Option<Self> {
105 let Value::Object(obj) = v else {
106 return None;
107 };
108 let mut b = BillingBillResourceInvoicingParentsInvoiceParentBuilder::deser_default();
109 for (k, v) in obj {
110 match k.as_str() {
111 "quote_details" => b.quote_details = FromValueOpt::from_value(v),
112 "subscription_details" => b.subscription_details = FromValueOpt::from_value(v),
113 "type" => b.type_ = FromValueOpt::from_value(v),
114 _ => {}
115 }
116 }
117 b.take_out()
118 }
119 }
120};
121#[derive(Copy, Clone, Eq, PartialEq)]
123pub enum BillingBillResourceInvoicingParentsInvoiceParentType {
124 QuoteDetails,
125 SubscriptionDetails,
126}
127impl BillingBillResourceInvoicingParentsInvoiceParentType {
128 pub fn as_str(self) -> &'static str {
129 use BillingBillResourceInvoicingParentsInvoiceParentType::*;
130 match self {
131 QuoteDetails => "quote_details",
132 SubscriptionDetails => "subscription_details",
133 }
134 }
135}
136
137impl std::str::FromStr for BillingBillResourceInvoicingParentsInvoiceParentType {
138 type Err = stripe_types::StripeParseError;
139 fn from_str(s: &str) -> Result<Self, Self::Err> {
140 use BillingBillResourceInvoicingParentsInvoiceParentType::*;
141 match s {
142 "quote_details" => Ok(QuoteDetails),
143 "subscription_details" => Ok(SubscriptionDetails),
144 _ => Err(stripe_types::StripeParseError),
145 }
146 }
147}
148impl std::fmt::Display for BillingBillResourceInvoicingParentsInvoiceParentType {
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 BillingBillResourceInvoicingParentsInvoiceParentType {
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 BillingBillResourceInvoicingParentsInvoiceParentType {
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 BillingBillResourceInvoicingParentsInvoiceParentType {
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<BillingBillResourceInvoicingParentsInvoiceParentType> {
175 fn string(&mut self, s: &str) -> miniserde::Result<()> {
176 use std::str::FromStr;
177 self.out = Some(
178 BillingBillResourceInvoicingParentsInvoiceParentType::from_str(s)
179 .map_err(|_| miniserde::Error)?,
180 );
181 Ok(())
182 }
183}
184
185stripe_types::impl_from_val_with_from_str!(BillingBillResourceInvoicingParentsInvoiceParentType);
186#[cfg(feature = "deserialize")]
187impl<'de> serde::Deserialize<'de> for BillingBillResourceInvoicingParentsInvoiceParentType {
188 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
189 use std::str::FromStr;
190 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
191 Self::from_str(&s).map_err(|_| {
192 serde::de::Error::custom(
193 "Unknown value for BillingBillResourceInvoicingParentsInvoiceParentType",
194 )
195 })
196 }
197}