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