stripe_shared/
subscription_pending_invoice_item_interval.rs1#[derive(Copy, Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct SubscriptionPendingInvoiceItemInterval {
5 pub interval: SubscriptionPendingInvoiceItemIntervalInterval,
7 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
61 _ => <dyn Visitor>::ignore(),
62 })
63 }
64
65 fn deser_default() -> Self {
66 Self { interval: Deserialize::default(), interval_count: Deserialize::default() }
67 }
68
69 fn take_out(&mut self) -> Option<Self::Out> {
70 let (Some(interval), Some(interval_count)) = (self.interval, 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 }
107 b.take_out()
108 }
109 }
110};
111#[derive(Copy, Clone, Eq, PartialEq)]
113pub enum SubscriptionPendingInvoiceItemIntervalInterval {
114 Day,
115 Month,
116 Week,
117 Year,
118}
119impl SubscriptionPendingInvoiceItemIntervalInterval {
120 pub fn as_str(self) -> &'static str {
121 use SubscriptionPendingInvoiceItemIntervalInterval::*;
122 match self {
123 Day => "day",
124 Month => "month",
125 Week => "week",
126 Year => "year",
127 }
128 }
129}
130
131impl std::str::FromStr for SubscriptionPendingInvoiceItemIntervalInterval {
132 type Err = stripe_types::StripeParseError;
133 fn from_str(s: &str) -> Result<Self, Self::Err> {
134 use SubscriptionPendingInvoiceItemIntervalInterval::*;
135 match s {
136 "day" => Ok(Day),
137 "month" => Ok(Month),
138 "week" => Ok(Week),
139 "year" => Ok(Year),
140 _ => Err(stripe_types::StripeParseError),
141 }
142 }
143}
144impl std::fmt::Display for SubscriptionPendingInvoiceItemIntervalInterval {
145 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
146 f.write_str(self.as_str())
147 }
148}
149
150impl std::fmt::Debug for SubscriptionPendingInvoiceItemIntervalInterval {
151 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
152 f.write_str(self.as_str())
153 }
154}
155#[cfg(feature = "serialize")]
156impl serde::Serialize for SubscriptionPendingInvoiceItemIntervalInterval {
157 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
158 where
159 S: serde::Serializer,
160 {
161 serializer.serialize_str(self.as_str())
162 }
163}
164impl miniserde::Deserialize for SubscriptionPendingInvoiceItemIntervalInterval {
165 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
166 crate::Place::new(out)
167 }
168}
169
170impl miniserde::de::Visitor for crate::Place<SubscriptionPendingInvoiceItemIntervalInterval> {
171 fn string(&mut self, s: &str) -> miniserde::Result<()> {
172 use std::str::FromStr;
173 self.out = Some(
174 SubscriptionPendingInvoiceItemIntervalInterval::from_str(s)
175 .map_err(|_| miniserde::Error)?,
176 );
177 Ok(())
178 }
179}
180
181stripe_types::impl_from_val_with_from_str!(SubscriptionPendingInvoiceItemIntervalInterval);
182#[cfg(feature = "deserialize")]
183impl<'de> serde::Deserialize<'de> for SubscriptionPendingInvoiceItemIntervalInterval {
184 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
185 use std::str::FromStr;
186 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
187 Self::from_str(&s).map_err(|_| {
188 serde::de::Error::custom(
189 "Unknown value for SubscriptionPendingInvoiceItemIntervalInterval",
190 )
191 })
192 }
193}