stripe_shared/
subscriptions_resource_billing_cycle_anchor_config.rs

1#[derive(Copy, Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct SubscriptionsResourceBillingCycleAnchorConfig {
5    /// The day of the month of the billing_cycle_anchor.
6    pub day_of_month: i64,
7    /// The hour of the day of the billing_cycle_anchor.
8    pub hour: Option<i64>,
9    /// The minute of the hour of the billing_cycle_anchor.
10    pub minute: Option<i64>,
11    /// The month to start full cycle billing periods.
12    pub month: Option<i64>,
13    /// The second of the minute of the billing_cycle_anchor.
14    pub second: Option<i64>,
15}
16#[doc(hidden)]
17pub struct SubscriptionsResourceBillingCycleAnchorConfigBuilder {
18    day_of_month: Option<i64>,
19    hour: Option<Option<i64>>,
20    minute: Option<Option<i64>>,
21    month: Option<Option<i64>>,
22    second: Option<Option<i64>>,
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 SubscriptionsResourceBillingCycleAnchorConfig {
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<SubscriptionsResourceBillingCycleAnchorConfig>,
49        builder: SubscriptionsResourceBillingCycleAnchorConfigBuilder,
50    }
51
52    impl Visitor for Place<SubscriptionsResourceBillingCycleAnchorConfig> {
53        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
54            Ok(Box::new(Builder {
55                out: &mut self.out,
56                builder: SubscriptionsResourceBillingCycleAnchorConfigBuilder::deser_default(),
57            }))
58        }
59    }
60
61    impl MapBuilder for SubscriptionsResourceBillingCycleAnchorConfigBuilder {
62        type Out = SubscriptionsResourceBillingCycleAnchorConfig;
63        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
64            Ok(match k {
65                "day_of_month" => Deserialize::begin(&mut self.day_of_month),
66                "hour" => Deserialize::begin(&mut self.hour),
67                "minute" => Deserialize::begin(&mut self.minute),
68                "month" => Deserialize::begin(&mut self.month),
69                "second" => Deserialize::begin(&mut self.second),
70
71                _ => <dyn Visitor>::ignore(),
72            })
73        }
74
75        fn deser_default() -> Self {
76            Self {
77                day_of_month: Deserialize::default(),
78                hour: Deserialize::default(),
79                minute: Deserialize::default(),
80                month: Deserialize::default(),
81                second: Deserialize::default(),
82            }
83        }
84
85        fn take_out(&mut self) -> Option<Self::Out> {
86            let (Some(day_of_month), Some(hour), Some(minute), Some(month), Some(second)) =
87                (self.day_of_month, self.hour, self.minute, self.month, self.second)
88            else {
89                return None;
90            };
91            Some(Self::Out { day_of_month, hour, minute, month, second })
92        }
93    }
94
95    impl Map for Builder<'_> {
96        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
97            self.builder.key(k)
98        }
99
100        fn finish(&mut self) -> Result<()> {
101            *self.out = self.builder.take_out();
102            Ok(())
103        }
104    }
105
106    impl ObjectDeser for SubscriptionsResourceBillingCycleAnchorConfig {
107        type Builder = SubscriptionsResourceBillingCycleAnchorConfigBuilder;
108    }
109
110    impl FromValueOpt for SubscriptionsResourceBillingCycleAnchorConfig {
111        fn from_value(v: Value) -> Option<Self> {
112            let Value::Object(obj) = v else {
113                return None;
114            };
115            let mut b = SubscriptionsResourceBillingCycleAnchorConfigBuilder::deser_default();
116            for (k, v) in obj {
117                match k.as_str() {
118                    "day_of_month" => b.day_of_month = FromValueOpt::from_value(v),
119                    "hour" => b.hour = FromValueOpt::from_value(v),
120                    "minute" => b.minute = FromValueOpt::from_value(v),
121                    "month" => b.month = FromValueOpt::from_value(v),
122                    "second" => b.second = FromValueOpt::from_value(v),
123
124                    _ => {}
125                }
126            }
127            b.take_out()
128        }
129    }
130};