stripe_shared/
subscriptions_resource_billing_cycle_anchor_config.rs1#[derive(Copy, Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct SubscriptionsResourceBillingCycleAnchorConfig {
5 pub day_of_month: i64,
7 pub hour: Option<i64>,
9 pub minute: Option<i64>,
11 pub month: Option<i64>,
13 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 _ => <dyn Visitor>::ignore(),
71 })
72 }
73
74 fn deser_default() -> Self {
75 Self {
76 day_of_month: Deserialize::default(),
77 hour: Deserialize::default(),
78 minute: Deserialize::default(),
79 month: Deserialize::default(),
80 second: Deserialize::default(),
81 }
82 }
83
84 fn take_out(&mut self) -> Option<Self::Out> {
85 let (Some(day_of_month), Some(hour), Some(minute), Some(month), Some(second)) =
86 (self.day_of_month, self.hour, self.minute, self.month, self.second)
87 else {
88 return None;
89 };
90 Some(Self::Out { day_of_month, hour, minute, month, second })
91 }
92 }
93
94 impl Map for Builder<'_> {
95 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
96 self.builder.key(k)
97 }
98
99 fn finish(&mut self) -> Result<()> {
100 *self.out = self.builder.take_out();
101 Ok(())
102 }
103 }
104
105 impl ObjectDeser for SubscriptionsResourceBillingCycleAnchorConfig {
106 type Builder = SubscriptionsResourceBillingCycleAnchorConfigBuilder;
107 }
108
109 impl FromValueOpt for SubscriptionsResourceBillingCycleAnchorConfig {
110 fn from_value(v: Value) -> Option<Self> {
111 let Value::Object(obj) = v else {
112 return None;
113 };
114 let mut b = SubscriptionsResourceBillingCycleAnchorConfigBuilder::deser_default();
115 for (k, v) in obj {
116 match k.as_str() {
117 "day_of_month" => b.day_of_month = FromValueOpt::from_value(v),
118 "hour" => b.hour = FromValueOpt::from_value(v),
119 "minute" => b.minute = FromValueOpt::from_value(v),
120 "month" => b.month = FromValueOpt::from_value(v),
121 "second" => b.second = FromValueOpt::from_value(v),
122 _ => {}
123 }
124 }
125 b.take_out()
126 }
127 }
128};