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