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
67 _ => <dyn Visitor>::ignore(),
68 })
69 }
70
71 fn deser_default() -> Self {
72 Self {
73 quote_details: Deserialize::default(),
74 subscription_details: Deserialize::default(),
75 type_: Deserialize::default(),
76 }
77 }
78
79 fn take_out(&mut self) -> Option<Self::Out> {
80 let (Some(quote_details), Some(subscription_details), Some(type_)) =
81 (self.quote_details.take(), self.subscription_details.take(), self.type_)
82 else {
83 return None;
84 };
85 Some(Self::Out { quote_details, subscription_details, type_ })
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 BillingBillResourceInvoicingParentsInvoiceParent {
101 type Builder = BillingBillResourceInvoicingParentsInvoiceParentBuilder;
102 }
103
104 impl FromValueOpt for BillingBillResourceInvoicingParentsInvoiceParent {
105 fn from_value(v: Value) -> Option<Self> {
106 let Value::Object(obj) = v else {
107 return None;
108 };
109 let mut b = BillingBillResourceInvoicingParentsInvoiceParentBuilder::deser_default();
110 for (k, v) in obj {
111 match k.as_str() {
112 "quote_details" => b.quote_details = FromValueOpt::from_value(v),
113 "subscription_details" => b.subscription_details = FromValueOpt::from_value(v),
114 "type" => b.type_ = FromValueOpt::from_value(v),
115
116 _ => {}
117 }
118 }
119 b.take_out()
120 }
121 }
122};
123#[derive(Copy, Clone, Eq, PartialEq)]
125pub enum BillingBillResourceInvoicingParentsInvoiceParentType {
126 QuoteDetails,
127 SubscriptionDetails,
128}
129impl BillingBillResourceInvoicingParentsInvoiceParentType {
130 pub fn as_str(self) -> &'static str {
131 use BillingBillResourceInvoicingParentsInvoiceParentType::*;
132 match self {
133 QuoteDetails => "quote_details",
134 SubscriptionDetails => "subscription_details",
135 }
136 }
137}
138
139impl std::str::FromStr for BillingBillResourceInvoicingParentsInvoiceParentType {
140 type Err = stripe_types::StripeParseError;
141 fn from_str(s: &str) -> Result<Self, Self::Err> {
142 use BillingBillResourceInvoicingParentsInvoiceParentType::*;
143 match s {
144 "quote_details" => Ok(QuoteDetails),
145 "subscription_details" => Ok(SubscriptionDetails),
146 _ => Err(stripe_types::StripeParseError),
147 }
148 }
149}
150impl std::fmt::Display for BillingBillResourceInvoicingParentsInvoiceParentType {
151 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
152 f.write_str(self.as_str())
153 }
154}
155
156impl std::fmt::Debug for BillingBillResourceInvoicingParentsInvoiceParentType {
157 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
158 f.write_str(self.as_str())
159 }
160}
161#[cfg(feature = "serialize")]
162impl serde::Serialize for BillingBillResourceInvoicingParentsInvoiceParentType {
163 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
164 where
165 S: serde::Serializer,
166 {
167 serializer.serialize_str(self.as_str())
168 }
169}
170impl miniserde::Deserialize for BillingBillResourceInvoicingParentsInvoiceParentType {
171 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
172 crate::Place::new(out)
173 }
174}
175
176impl miniserde::de::Visitor for crate::Place<BillingBillResourceInvoicingParentsInvoiceParentType> {
177 fn string(&mut self, s: &str) -> miniserde::Result<()> {
178 use std::str::FromStr;
179 self.out = Some(
180 BillingBillResourceInvoicingParentsInvoiceParentType::from_str(s)
181 .map_err(|_| miniserde::Error)?,
182 );
183 Ok(())
184 }
185}
186
187stripe_types::impl_from_val_with_from_str!(BillingBillResourceInvoicingParentsInvoiceParentType);
188#[cfg(feature = "deserialize")]
189impl<'de> serde::Deserialize<'de> for BillingBillResourceInvoicingParentsInvoiceParentType {
190 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
191 use std::str::FromStr;
192 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
193 Self::from_str(&s).map_err(|_| {
194 serde::de::Error::custom(
195 "Unknown value for BillingBillResourceInvoicingParentsInvoiceParentType",
196 )
197 })
198 }
199}