stripe_shared/
subscriptions_resource_billing_mode_flexible.rs

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