stripe_shared/
billing_bill_resource_invoicing_parents_invoice_parent.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct BillingBillResourceInvoicingParentsInvoiceParent {
5    /// Details about the quote that generated this invoice
6    pub quote_details: Option<stripe_shared::BillingBillResourceInvoicingParentsInvoiceQuoteParent>,
7    /// Details about the subscription that generated this invoice
8    pub subscription_details:
9        Option<stripe_shared::BillingBillResourceInvoicingParentsInvoiceSubscriptionParent>,
10    /// The type of parent that generated this invoice
11    #[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_.take())
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/// The type of parent that generated this invoice
122#[derive(Clone, Eq, PartialEq)]
123#[non_exhaustive]
124pub enum BillingBillResourceInvoicingParentsInvoiceParentType {
125    QuoteDetails,
126    SubscriptionDetails,
127    /// An unrecognized value from Stripe. Should not be used as a request parameter.
128    Unknown(String),
129}
130impl BillingBillResourceInvoicingParentsInvoiceParentType {
131    pub fn as_str(&self) -> &str {
132        use BillingBillResourceInvoicingParentsInvoiceParentType::*;
133        match self {
134            QuoteDetails => "quote_details",
135            SubscriptionDetails => "subscription_details",
136            Unknown(v) => v,
137        }
138    }
139}
140
141impl std::str::FromStr for BillingBillResourceInvoicingParentsInvoiceParentType {
142    type Err = std::convert::Infallible;
143    fn from_str(s: &str) -> Result<Self, Self::Err> {
144        use BillingBillResourceInvoicingParentsInvoiceParentType::*;
145        match s {
146            "quote_details" => Ok(QuoteDetails),
147            "subscription_details" => Ok(SubscriptionDetails),
148            v => {
149                tracing::warn!(
150                    "Unknown value '{}' for enum '{}'",
151                    v,
152                    "BillingBillResourceInvoicingParentsInvoiceParentType"
153                );
154                Ok(Unknown(v.to_owned()))
155            }
156        }
157    }
158}
159impl std::fmt::Display for BillingBillResourceInvoicingParentsInvoiceParentType {
160    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
161        f.write_str(self.as_str())
162    }
163}
164
165impl std::fmt::Debug for BillingBillResourceInvoicingParentsInvoiceParentType {
166    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
167        f.write_str(self.as_str())
168    }
169}
170#[cfg(feature = "serialize")]
171impl serde::Serialize for BillingBillResourceInvoicingParentsInvoiceParentType {
172    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
173    where
174        S: serde::Serializer,
175    {
176        serializer.serialize_str(self.as_str())
177    }
178}
179impl miniserde::Deserialize for BillingBillResourceInvoicingParentsInvoiceParentType {
180    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
181        crate::Place::new(out)
182    }
183}
184
185impl miniserde::de::Visitor for crate::Place<BillingBillResourceInvoicingParentsInvoiceParentType> {
186    fn string(&mut self, s: &str) -> miniserde::Result<()> {
187        use std::str::FromStr;
188        self.out = Some(
189            BillingBillResourceInvoicingParentsInvoiceParentType::from_str(s).expect("infallible"),
190        );
191        Ok(())
192    }
193}
194
195stripe_types::impl_from_val_with_from_str!(BillingBillResourceInvoicingParentsInvoiceParentType);
196#[cfg(feature = "deserialize")]
197impl<'de> serde::Deserialize<'de> for BillingBillResourceInvoicingParentsInvoiceParentType {
198    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
199        use std::str::FromStr;
200        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
201        Ok(Self::from_str(&s).expect("infallible"))
202    }
203}