Skip to main content

stripe_shared/
subscriptions_resource_billing_cycle_anchor_config.rs

1#[derive(Copy, Clone, Eq, PartialEq)]
2#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct SubscriptionsResourceBillingCycleAnchorConfig {
6    /// The day of the month of the billing_cycle_anchor.
7    pub day_of_month: i64,
8    /// The hour of the day of the billing_cycle_anchor.
9    pub hour: Option<i64>,
10    /// The minute of the hour of the billing_cycle_anchor.
11    pub minute: Option<i64>,
12    /// The month to start full cycle billing periods.
13    pub month: Option<i64>,
14    /// The second of the minute of the billing_cycle_anchor.
15    pub second: Option<i64>,
16}
17#[cfg(feature = "redact-generated-debug")]
18impl std::fmt::Debug for SubscriptionsResourceBillingCycleAnchorConfig {
19    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
20        f.debug_struct("SubscriptionsResourceBillingCycleAnchorConfig").finish_non_exhaustive()
21    }
22}
23#[doc(hidden)]
24pub struct SubscriptionsResourceBillingCycleAnchorConfigBuilder {
25    day_of_month: Option<i64>,
26    hour: Option<Option<i64>>,
27    minute: Option<Option<i64>>,
28    month: Option<Option<i64>>,
29    second: Option<Option<i64>>,
30}
31
32#[allow(
33    unused_variables,
34    irrefutable_let_patterns,
35    clippy::let_unit_value,
36    clippy::match_single_binding,
37    clippy::single_match
38)]
39const _: () = {
40    use miniserde::de::{Map, Visitor};
41    use miniserde::json::Value;
42    use miniserde::{Deserialize, Result, make_place};
43    use stripe_types::miniserde_helpers::FromValueOpt;
44    use stripe_types::{MapBuilder, ObjectDeser};
45
46    make_place!(Place);
47
48    impl Deserialize for SubscriptionsResourceBillingCycleAnchorConfig {
49        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
50            Place::new(out)
51        }
52    }
53
54    struct Builder<'a> {
55        out: &'a mut Option<SubscriptionsResourceBillingCycleAnchorConfig>,
56        builder: SubscriptionsResourceBillingCycleAnchorConfigBuilder,
57    }
58
59    impl Visitor for Place<SubscriptionsResourceBillingCycleAnchorConfig> {
60        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
61            Ok(Box::new(Builder {
62                out: &mut self.out,
63                builder: SubscriptionsResourceBillingCycleAnchorConfigBuilder::deser_default(),
64            }))
65        }
66    }
67
68    impl MapBuilder for SubscriptionsResourceBillingCycleAnchorConfigBuilder {
69        type Out = SubscriptionsResourceBillingCycleAnchorConfig;
70        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
71            Ok(match k {
72                "day_of_month" => Deserialize::begin(&mut self.day_of_month),
73                "hour" => Deserialize::begin(&mut self.hour),
74                "minute" => Deserialize::begin(&mut self.minute),
75                "month" => Deserialize::begin(&mut self.month),
76                "second" => Deserialize::begin(&mut self.second),
77                _ => <dyn Visitor>::ignore(),
78            })
79        }
80
81        fn deser_default() -> Self {
82            Self {
83                day_of_month: None,
84                hour: Some(None),
85                minute: Some(None),
86                month: Some(None),
87                second: Some(None),
88            }
89        }
90
91        fn take_out(&mut self) -> Option<Self::Out> {
92            let (Some(day_of_month), Some(hour), Some(minute), Some(month), Some(second)) =
93                (self.day_of_month, self.hour, self.minute, self.month, self.second)
94            else {
95                return None;
96            };
97            Some(Self::Out { day_of_month, hour, minute, month, second })
98        }
99    }
100
101    impl Map for Builder<'_> {
102        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
103            self.builder.key(k)
104        }
105
106        fn finish(&mut self) -> Result<()> {
107            *self.out = self.builder.take_out();
108            Ok(())
109        }
110    }
111
112    impl ObjectDeser for SubscriptionsResourceBillingCycleAnchorConfig {
113        type Builder = SubscriptionsResourceBillingCycleAnchorConfigBuilder;
114    }
115
116    impl FromValueOpt for SubscriptionsResourceBillingCycleAnchorConfig {
117        fn from_value(v: Value) -> Option<Self> {
118            let Value::Object(obj) = v else {
119                return None;
120            };
121            let mut b = SubscriptionsResourceBillingCycleAnchorConfigBuilder::deser_default();
122            for (k, v) in obj {
123                match k.as_str() {
124                    "day_of_month" => b.day_of_month = FromValueOpt::from_value(v),
125                    "hour" => b.hour = FromValueOpt::from_value(v),
126                    "minute" => b.minute = FromValueOpt::from_value(v),
127                    "month" => b.month = FromValueOpt::from_value(v),
128                    "second" => b.second = FromValueOpt::from_value(v),
129                    _ => {}
130                }
131            }
132            b.take_out()
133        }
134    }
135};