stripe_shared/
billing_bill_resource_invoicing_pricing_pricing.rs

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