stripe_shared/
subscriptions_resource_billing_schedules_applies_to.rs1#[derive(Clone)]
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 SubscriptionsResourceBillingSchedulesAppliesTo {
7 pub price: Option<stripe_types::Expandable<stripe_shared::Price>>,
9 #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
11 pub type_: SubscriptionsResourceBillingSchedulesAppliesToType,
12}
13#[cfg(feature = "redact-generated-debug")]
14impl std::fmt::Debug for SubscriptionsResourceBillingSchedulesAppliesTo {
15 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
16 f.debug_struct("SubscriptionsResourceBillingSchedulesAppliesTo").finish_non_exhaustive()
17 }
18}
19#[doc(hidden)]
20pub struct SubscriptionsResourceBillingSchedulesAppliesToBuilder {
21 price: Option<Option<stripe_types::Expandable<stripe_shared::Price>>>,
22 type_: Option<SubscriptionsResourceBillingSchedulesAppliesToType>,
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 SubscriptionsResourceBillingSchedulesAppliesTo {
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<SubscriptionsResourceBillingSchedulesAppliesTo>,
49 builder: SubscriptionsResourceBillingSchedulesAppliesToBuilder,
50 }
51
52 impl Visitor for Place<SubscriptionsResourceBillingSchedulesAppliesTo> {
53 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
54 Ok(Box::new(Builder {
55 out: &mut self.out,
56 builder: SubscriptionsResourceBillingSchedulesAppliesToBuilder::deser_default(),
57 }))
58 }
59 }
60
61 impl MapBuilder for SubscriptionsResourceBillingSchedulesAppliesToBuilder {
62 type Out = SubscriptionsResourceBillingSchedulesAppliesTo;
63 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
64 Ok(match k {
65 "price" => Deserialize::begin(&mut self.price),
66 "type" => Deserialize::begin(&mut self.type_),
67 _ => <dyn Visitor>::ignore(),
68 })
69 }
70
71 fn deser_default() -> Self {
72 Self { price: Some(None), type_: None }
73 }
74
75 fn take_out(&mut self) -> Option<Self::Out> {
76 let (Some(price), Some(type_)) = (self.price.take(), self.type_.take()) else {
77 return None;
78 };
79 Some(Self::Out { price, type_ })
80 }
81 }
82
83 impl Map for Builder<'_> {
84 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
85 self.builder.key(k)
86 }
87
88 fn finish(&mut self) -> Result<()> {
89 *self.out = self.builder.take_out();
90 Ok(())
91 }
92 }
93
94 impl ObjectDeser for SubscriptionsResourceBillingSchedulesAppliesTo {
95 type Builder = SubscriptionsResourceBillingSchedulesAppliesToBuilder;
96 }
97
98 impl FromValueOpt for SubscriptionsResourceBillingSchedulesAppliesTo {
99 fn from_value(v: Value) -> Option<Self> {
100 let Value::Object(obj) = v else {
101 return None;
102 };
103 let mut b = SubscriptionsResourceBillingSchedulesAppliesToBuilder::deser_default();
104 for (k, v) in obj {
105 match k.as_str() {
106 "price" => b.price = FromValueOpt::from_value(v),
107 "type" => b.type_ = FromValueOpt::from_value(v),
108 _ => {}
109 }
110 }
111 b.take_out()
112 }
113 }
114};
115#[derive(Clone, Eq, PartialEq)]
117#[non_exhaustive]
118pub enum SubscriptionsResourceBillingSchedulesAppliesToType {
119 Price,
120 Unknown(String),
122}
123impl SubscriptionsResourceBillingSchedulesAppliesToType {
124 pub fn as_str(&self) -> &str {
125 use SubscriptionsResourceBillingSchedulesAppliesToType::*;
126 match self {
127 Price => "price",
128 Unknown(v) => v,
129 }
130 }
131}
132
133impl std::str::FromStr for SubscriptionsResourceBillingSchedulesAppliesToType {
134 type Err = std::convert::Infallible;
135 fn from_str(s: &str) -> Result<Self, Self::Err> {
136 use SubscriptionsResourceBillingSchedulesAppliesToType::*;
137 match s {
138 "price" => Ok(Price),
139 v => {
140 tracing::warn!(
141 "Unknown value '{}' for enum '{}'",
142 v,
143 "SubscriptionsResourceBillingSchedulesAppliesToType"
144 );
145 Ok(Unknown(v.to_owned()))
146 }
147 }
148 }
149}
150impl std::fmt::Display for SubscriptionsResourceBillingSchedulesAppliesToType {
151 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
152 f.write_str(self.as_str())
153 }
154}
155
156#[cfg(not(feature = "redact-generated-debug"))]
157impl std::fmt::Debug for SubscriptionsResourceBillingSchedulesAppliesToType {
158 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
159 f.write_str(self.as_str())
160 }
161}
162#[cfg(feature = "redact-generated-debug")]
163impl std::fmt::Debug for SubscriptionsResourceBillingSchedulesAppliesToType {
164 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
165 f.debug_struct(stringify!(SubscriptionsResourceBillingSchedulesAppliesToType))
166 .finish_non_exhaustive()
167 }
168}
169#[cfg(feature = "serialize")]
170impl serde::Serialize for SubscriptionsResourceBillingSchedulesAppliesToType {
171 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
172 where
173 S: serde::Serializer,
174 {
175 serializer.serialize_str(self.as_str())
176 }
177}
178impl miniserde::Deserialize for SubscriptionsResourceBillingSchedulesAppliesToType {
179 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
180 crate::Place::new(out)
181 }
182}
183
184impl miniserde::de::Visitor for crate::Place<SubscriptionsResourceBillingSchedulesAppliesToType> {
185 fn string(&mut self, s: &str) -> miniserde::Result<()> {
186 use std::str::FromStr;
187 self.out = Some(
188 SubscriptionsResourceBillingSchedulesAppliesToType::from_str(s).expect("infallible"),
189 );
190 Ok(())
191 }
192}
193
194stripe_types::impl_from_val_with_from_str!(SubscriptionsResourceBillingSchedulesAppliesToType);
195#[cfg(feature = "deserialize")]
196impl<'de> serde::Deserialize<'de> for SubscriptionsResourceBillingSchedulesAppliesToType {
197 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
198 use std::str::FromStr;
199 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
200 Ok(Self::from_str(&s).expect("infallible"))
201 }
202}