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