Skip to main content

stripe_shared/
subscriptions_resource_billing_schedules_bill_until_duration.rs

1/// Configures the `bill_until` date based on the provided `interval` and `interval_count`.
2#[derive(Clone, Eq, PartialEq)]
3#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
4#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
5#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
6pub struct SubscriptionsResourceBillingSchedulesBillUntilDuration {
7    /// Specifies billing duration. Either `day`, `week`, `month` or `year`.
8    pub interval: SubscriptionsResourceBillingSchedulesBillUntilDurationInterval,
9    /// The multiplier applied to the interval.
10    pub interval_count: Option<u64>,
11}
12#[cfg(feature = "redact-generated-debug")]
13impl std::fmt::Debug for SubscriptionsResourceBillingSchedulesBillUntilDuration {
14    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
15        f.debug_struct("SubscriptionsResourceBillingSchedulesBillUntilDuration")
16            .finish_non_exhaustive()
17    }
18}
19#[doc(hidden)]
20pub struct SubscriptionsResourceBillingSchedulesBillUntilDurationBuilder {
21    interval: Option<SubscriptionsResourceBillingSchedulesBillUntilDurationInterval>,
22    interval_count: Option<Option<u64>>,
23}
24
25#[allow(
26    unused_variables,
27    irrefutable_let_patterns,
28    clippy::let_unit_value,
29    clippy::match_single_binding,
30    clippy::single_match
31)]
32const _: () = {
33    use miniserde::de::{Map, Visitor};
34    use miniserde::json::Value;
35    use miniserde::{Deserialize, Result, make_place};
36    use stripe_types::miniserde_helpers::FromValueOpt;
37    use stripe_types::{MapBuilder, ObjectDeser};
38
39    make_place!(Place);
40
41    impl Deserialize for SubscriptionsResourceBillingSchedulesBillUntilDuration {
42        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
43            Place::new(out)
44        }
45    }
46
47    struct Builder<'a> {
48        out: &'a mut Option<SubscriptionsResourceBillingSchedulesBillUntilDuration>,
49        builder: SubscriptionsResourceBillingSchedulesBillUntilDurationBuilder,
50    }
51
52    impl Visitor for Place<SubscriptionsResourceBillingSchedulesBillUntilDuration> {
53        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
54            Ok(Box::new(Builder {
55                out: &mut self.out,
56                builder:
57                    SubscriptionsResourceBillingSchedulesBillUntilDurationBuilder::deser_default(),
58            }))
59        }
60    }
61
62    impl MapBuilder for SubscriptionsResourceBillingSchedulesBillUntilDurationBuilder {
63        type Out = SubscriptionsResourceBillingSchedulesBillUntilDuration;
64        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
65            Ok(match k {
66                "interval" => Deserialize::begin(&mut self.interval),
67                "interval_count" => Deserialize::begin(&mut self.interval_count),
68                _ => <dyn Visitor>::ignore(),
69            })
70        }
71
72        fn deser_default() -> Self {
73            Self { interval: None, interval_count: Some(None) }
74        }
75
76        fn take_out(&mut self) -> Option<Self::Out> {
77            let (Some(interval), Some(interval_count)) =
78                (self.interval.take(), self.interval_count)
79            else {
80                return None;
81            };
82            Some(Self::Out { interval, interval_count })
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 SubscriptionsResourceBillingSchedulesBillUntilDuration {
98        type Builder = SubscriptionsResourceBillingSchedulesBillUntilDurationBuilder;
99    }
100
101    impl FromValueOpt for SubscriptionsResourceBillingSchedulesBillUntilDuration {
102        fn from_value(v: Value) -> Option<Self> {
103            let Value::Object(obj) = v else {
104                return None;
105            };
106            let mut b =
107                SubscriptionsResourceBillingSchedulesBillUntilDurationBuilder::deser_default();
108            for (k, v) in obj {
109                match k.as_str() {
110                    "interval" => b.interval = FromValueOpt::from_value(v),
111                    "interval_count" => b.interval_count = FromValueOpt::from_value(v),
112                    _ => {}
113                }
114            }
115            b.take_out()
116        }
117    }
118};
119/// Specifies billing duration. Either `day`, `week`, `month` or `year`.
120#[derive(Clone, Eq, PartialEq)]
121#[non_exhaustive]
122pub enum SubscriptionsResourceBillingSchedulesBillUntilDurationInterval {
123    Day,
124    Month,
125    Week,
126    Year,
127    /// An unrecognized value from Stripe. Should not be used as a request parameter.
128    Unknown(String),
129}
130impl SubscriptionsResourceBillingSchedulesBillUntilDurationInterval {
131    pub fn as_str(&self) -> &str {
132        use SubscriptionsResourceBillingSchedulesBillUntilDurationInterval::*;
133        match self {
134            Day => "day",
135            Month => "month",
136            Week => "week",
137            Year => "year",
138            Unknown(v) => v,
139        }
140    }
141}
142
143impl std::str::FromStr for SubscriptionsResourceBillingSchedulesBillUntilDurationInterval {
144    type Err = std::convert::Infallible;
145    fn from_str(s: &str) -> Result<Self, Self::Err> {
146        use SubscriptionsResourceBillingSchedulesBillUntilDurationInterval::*;
147        match s {
148            "day" => Ok(Day),
149            "month" => Ok(Month),
150            "week" => Ok(Week),
151            "year" => Ok(Year),
152            v => {
153                tracing::warn!(
154                    "Unknown value '{}' for enum '{}'",
155                    v,
156                    "SubscriptionsResourceBillingSchedulesBillUntilDurationInterval"
157                );
158                Ok(Unknown(v.to_owned()))
159            }
160        }
161    }
162}
163impl std::fmt::Display for SubscriptionsResourceBillingSchedulesBillUntilDurationInterval {
164    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
165        f.write_str(self.as_str())
166    }
167}
168
169#[cfg(not(feature = "redact-generated-debug"))]
170impl std::fmt::Debug for SubscriptionsResourceBillingSchedulesBillUntilDurationInterval {
171    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
172        f.write_str(self.as_str())
173    }
174}
175#[cfg(feature = "redact-generated-debug")]
176impl std::fmt::Debug for SubscriptionsResourceBillingSchedulesBillUntilDurationInterval {
177    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
178        f.debug_struct(stringify!(SubscriptionsResourceBillingSchedulesBillUntilDurationInterval))
179            .finish_non_exhaustive()
180    }
181}
182#[cfg(feature = "serialize")]
183impl serde::Serialize for SubscriptionsResourceBillingSchedulesBillUntilDurationInterval {
184    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
185    where
186        S: serde::Serializer,
187    {
188        serializer.serialize_str(self.as_str())
189    }
190}
191impl miniserde::Deserialize for SubscriptionsResourceBillingSchedulesBillUntilDurationInterval {
192    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
193        crate::Place::new(out)
194    }
195}
196
197impl miniserde::de::Visitor
198    for crate::Place<SubscriptionsResourceBillingSchedulesBillUntilDurationInterval>
199{
200    fn string(&mut self, s: &str) -> miniserde::Result<()> {
201        use std::str::FromStr;
202        self.out = Some(
203            SubscriptionsResourceBillingSchedulesBillUntilDurationInterval::from_str(s)
204                .expect("infallible"),
205        );
206        Ok(())
207    }
208}
209
210stripe_types::impl_from_val_with_from_str!(
211    SubscriptionsResourceBillingSchedulesBillUntilDurationInterval
212);
213#[cfg(feature = "deserialize")]
214impl<'de> serde::Deserialize<'de>
215    for SubscriptionsResourceBillingSchedulesBillUntilDurationInterval
216{
217    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
218        use std::str::FromStr;
219        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
220        Ok(Self::from_str(&s).expect("infallible"))
221    }
222}