stripe_shared/
subscription_pending_invoice_item_interval.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct SubscriptionPendingInvoiceItemInterval {
5    /// Specifies invoicing frequency. Either `day`, `week`, `month` or `year`.
6    pub interval: SubscriptionPendingInvoiceItemIntervalInterval,
7    /// The number of intervals between invoices.
8    /// For example, `interval=month` and `interval_count=3` bills every 3 months.
9    /// Maximum of one year interval allowed (1 year, 12 months, or 52 weeks).
10    pub interval_count: u64,
11}
12#[doc(hidden)]
13pub struct SubscriptionPendingInvoiceItemIntervalBuilder {
14    interval: Option<SubscriptionPendingInvoiceItemIntervalInterval>,
15    interval_count: Option<u64>,
16}
17
18#[allow(
19    unused_variables,
20    irrefutable_let_patterns,
21    clippy::let_unit_value,
22    clippy::match_single_binding,
23    clippy::single_match
24)]
25const _: () = {
26    use miniserde::de::{Map, Visitor};
27    use miniserde::json::Value;
28    use miniserde::{Deserialize, Result, make_place};
29    use stripe_types::miniserde_helpers::FromValueOpt;
30    use stripe_types::{MapBuilder, ObjectDeser};
31
32    make_place!(Place);
33
34    impl Deserialize for SubscriptionPendingInvoiceItemInterval {
35        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
36            Place::new(out)
37        }
38    }
39
40    struct Builder<'a> {
41        out: &'a mut Option<SubscriptionPendingInvoiceItemInterval>,
42        builder: SubscriptionPendingInvoiceItemIntervalBuilder,
43    }
44
45    impl Visitor for Place<SubscriptionPendingInvoiceItemInterval> {
46        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
47            Ok(Box::new(Builder {
48                out: &mut self.out,
49                builder: SubscriptionPendingInvoiceItemIntervalBuilder::deser_default(),
50            }))
51        }
52    }
53
54    impl MapBuilder for SubscriptionPendingInvoiceItemIntervalBuilder {
55        type Out = SubscriptionPendingInvoiceItemInterval;
56        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
57            Ok(match k {
58                "interval" => Deserialize::begin(&mut self.interval),
59                "interval_count" => Deserialize::begin(&mut self.interval_count),
60                _ => <dyn Visitor>::ignore(),
61            })
62        }
63
64        fn deser_default() -> Self {
65            Self { interval: Deserialize::default(), interval_count: Deserialize::default() }
66        }
67
68        fn take_out(&mut self) -> Option<Self::Out> {
69            let (Some(interval), Some(interval_count)) =
70                (self.interval.take(), self.interval_count)
71            else {
72                return None;
73            };
74            Some(Self::Out { interval, interval_count })
75        }
76    }
77
78    impl Map for Builder<'_> {
79        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
80            self.builder.key(k)
81        }
82
83        fn finish(&mut self) -> Result<()> {
84            *self.out = self.builder.take_out();
85            Ok(())
86        }
87    }
88
89    impl ObjectDeser for SubscriptionPendingInvoiceItemInterval {
90        type Builder = SubscriptionPendingInvoiceItemIntervalBuilder;
91    }
92
93    impl FromValueOpt for SubscriptionPendingInvoiceItemInterval {
94        fn from_value(v: Value) -> Option<Self> {
95            let Value::Object(obj) = v else {
96                return None;
97            };
98            let mut b = SubscriptionPendingInvoiceItemIntervalBuilder::deser_default();
99            for (k, v) in obj {
100                match k.as_str() {
101                    "interval" => b.interval = FromValueOpt::from_value(v),
102                    "interval_count" => b.interval_count = FromValueOpt::from_value(v),
103                    _ => {}
104                }
105            }
106            b.take_out()
107        }
108    }
109};
110/// Specifies invoicing frequency. Either `day`, `week`, `month` or `year`.
111#[derive(Clone, Eq, PartialEq)]
112#[non_exhaustive]
113pub enum SubscriptionPendingInvoiceItemIntervalInterval {
114    Day,
115    Month,
116    Week,
117    Year,
118    /// An unrecognized value from Stripe. Should not be used as a request parameter.
119    Unknown(String),
120}
121impl SubscriptionPendingInvoiceItemIntervalInterval {
122    pub fn as_str(&self) -> &str {
123        use SubscriptionPendingInvoiceItemIntervalInterval::*;
124        match self {
125            Day => "day",
126            Month => "month",
127            Week => "week",
128            Year => "year",
129            Unknown(v) => v,
130        }
131    }
132}
133
134impl std::str::FromStr for SubscriptionPendingInvoiceItemIntervalInterval {
135    type Err = std::convert::Infallible;
136    fn from_str(s: &str) -> Result<Self, Self::Err> {
137        use SubscriptionPendingInvoiceItemIntervalInterval::*;
138        match s {
139            "day" => Ok(Day),
140            "month" => Ok(Month),
141            "week" => Ok(Week),
142            "year" => Ok(Year),
143            v => {
144                tracing::warn!(
145                    "Unknown value '{}' for enum '{}'",
146                    v,
147                    "SubscriptionPendingInvoiceItemIntervalInterval"
148                );
149                Ok(Unknown(v.to_owned()))
150            }
151        }
152    }
153}
154impl std::fmt::Display for SubscriptionPendingInvoiceItemIntervalInterval {
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 SubscriptionPendingInvoiceItemIntervalInterval {
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 SubscriptionPendingInvoiceItemIntervalInterval {
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 SubscriptionPendingInvoiceItemIntervalInterval {
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<SubscriptionPendingInvoiceItemIntervalInterval> {
181    fn string(&mut self, s: &str) -> miniserde::Result<()> {
182        use std::str::FromStr;
183        self.out =
184            Some(SubscriptionPendingInvoiceItemIntervalInterval::from_str(s).expect("infallible"));
185        Ok(())
186    }
187}
188
189stripe_types::impl_from_val_with_from_str!(SubscriptionPendingInvoiceItemIntervalInterval);
190#[cfg(feature = "deserialize")]
191impl<'de> serde::Deserialize<'de> for SubscriptionPendingInvoiceItemIntervalInterval {
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}