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