stripe_shared/
issuing_physical_bundle_features.rs

1#[derive(Copy, Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct IssuingPhysicalBundleFeatures {
5    /// The policy for how to use card logo images in a card design with this physical bundle.
6    pub card_logo: IssuingPhysicalBundleFeaturesCardLogo,
7    /// The policy for how to use carrier letter text in a card design with this physical bundle.
8    pub carrier_text: IssuingPhysicalBundleFeaturesCarrierText,
9    /// The policy for how to use a second line on a card with this physical bundle.
10    pub second_line: IssuingPhysicalBundleFeaturesSecondLine,
11}
12#[doc(hidden)]
13pub struct IssuingPhysicalBundleFeaturesBuilder {
14    card_logo: Option<IssuingPhysicalBundleFeaturesCardLogo>,
15    carrier_text: Option<IssuingPhysicalBundleFeaturesCarrierText>,
16    second_line: Option<IssuingPhysicalBundleFeaturesSecondLine>,
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::{make_place, Deserialize, Result};
30    use stripe_types::miniserde_helpers::FromValueOpt;
31    use stripe_types::{MapBuilder, ObjectDeser};
32
33    make_place!(Place);
34
35    impl Deserialize for IssuingPhysicalBundleFeatures {
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<IssuingPhysicalBundleFeatures>,
43        builder: IssuingPhysicalBundleFeaturesBuilder,
44    }
45
46    impl Visitor for Place<IssuingPhysicalBundleFeatures> {
47        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
48            Ok(Box::new(Builder {
49                out: &mut self.out,
50                builder: IssuingPhysicalBundleFeaturesBuilder::deser_default(),
51            }))
52        }
53    }
54
55    impl MapBuilder for IssuingPhysicalBundleFeaturesBuilder {
56        type Out = IssuingPhysicalBundleFeatures;
57        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
58            Ok(match k {
59                "card_logo" => Deserialize::begin(&mut self.card_logo),
60                "carrier_text" => Deserialize::begin(&mut self.carrier_text),
61                "second_line" => Deserialize::begin(&mut self.second_line),
62
63                _ => <dyn Visitor>::ignore(),
64            })
65        }
66
67        fn deser_default() -> Self {
68            Self {
69                card_logo: Deserialize::default(),
70                carrier_text: Deserialize::default(),
71                second_line: Deserialize::default(),
72            }
73        }
74
75        fn take_out(&mut self) -> Option<Self::Out> {
76            let (Some(card_logo), Some(carrier_text), Some(second_line)) =
77                (self.card_logo, self.carrier_text, self.second_line)
78            else {
79                return None;
80            };
81            Some(Self::Out { card_logo, carrier_text, second_line })
82        }
83    }
84
85    impl Map for Builder<'_> {
86        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
87            self.builder.key(k)
88        }
89
90        fn finish(&mut self) -> Result<()> {
91            *self.out = self.builder.take_out();
92            Ok(())
93        }
94    }
95
96    impl ObjectDeser for IssuingPhysicalBundleFeatures {
97        type Builder = IssuingPhysicalBundleFeaturesBuilder;
98    }
99
100    impl FromValueOpt for IssuingPhysicalBundleFeatures {
101        fn from_value(v: Value) -> Option<Self> {
102            let Value::Object(obj) = v else {
103                return None;
104            };
105            let mut b = IssuingPhysicalBundleFeaturesBuilder::deser_default();
106            for (k, v) in obj {
107                match k.as_str() {
108                    "card_logo" => b.card_logo = FromValueOpt::from_value(v),
109                    "carrier_text" => b.carrier_text = FromValueOpt::from_value(v),
110                    "second_line" => b.second_line = FromValueOpt::from_value(v),
111
112                    _ => {}
113                }
114            }
115            b.take_out()
116        }
117    }
118};
119/// The policy for how to use card logo images in a card design with this physical bundle.
120#[derive(Copy, Clone, Eq, PartialEq)]
121pub enum IssuingPhysicalBundleFeaturesCardLogo {
122    Optional,
123    Required,
124    Unsupported,
125}
126impl IssuingPhysicalBundleFeaturesCardLogo {
127    pub fn as_str(self) -> &'static str {
128        use IssuingPhysicalBundleFeaturesCardLogo::*;
129        match self {
130            Optional => "optional",
131            Required => "required",
132            Unsupported => "unsupported",
133        }
134    }
135}
136
137impl std::str::FromStr for IssuingPhysicalBundleFeaturesCardLogo {
138    type Err = stripe_types::StripeParseError;
139    fn from_str(s: &str) -> Result<Self, Self::Err> {
140        use IssuingPhysicalBundleFeaturesCardLogo::*;
141        match s {
142            "optional" => Ok(Optional),
143            "required" => Ok(Required),
144            "unsupported" => Ok(Unsupported),
145            _ => Err(stripe_types::StripeParseError),
146        }
147    }
148}
149impl std::fmt::Display for IssuingPhysicalBundleFeaturesCardLogo {
150    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
151        f.write_str(self.as_str())
152    }
153}
154
155impl std::fmt::Debug for IssuingPhysicalBundleFeaturesCardLogo {
156    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
157        f.write_str(self.as_str())
158    }
159}
160#[cfg(feature = "serialize")]
161impl serde::Serialize for IssuingPhysicalBundleFeaturesCardLogo {
162    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
163    where
164        S: serde::Serializer,
165    {
166        serializer.serialize_str(self.as_str())
167    }
168}
169impl miniserde::Deserialize for IssuingPhysicalBundleFeaturesCardLogo {
170    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
171        crate::Place::new(out)
172    }
173}
174
175impl miniserde::de::Visitor for crate::Place<IssuingPhysicalBundleFeaturesCardLogo> {
176    fn string(&mut self, s: &str) -> miniserde::Result<()> {
177        use std::str::FromStr;
178        self.out =
179            Some(IssuingPhysicalBundleFeaturesCardLogo::from_str(s).map_err(|_| miniserde::Error)?);
180        Ok(())
181    }
182}
183
184stripe_types::impl_from_val_with_from_str!(IssuingPhysicalBundleFeaturesCardLogo);
185#[cfg(feature = "deserialize")]
186impl<'de> serde::Deserialize<'de> for IssuingPhysicalBundleFeaturesCardLogo {
187    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
188        use std::str::FromStr;
189        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
190        Self::from_str(&s).map_err(|_| {
191            serde::de::Error::custom("Unknown value for IssuingPhysicalBundleFeaturesCardLogo")
192        })
193    }
194}
195/// The policy for how to use carrier letter text in a card design with this physical bundle.
196#[derive(Copy, Clone, Eq, PartialEq)]
197pub enum IssuingPhysicalBundleFeaturesCarrierText {
198    Optional,
199    Required,
200    Unsupported,
201}
202impl IssuingPhysicalBundleFeaturesCarrierText {
203    pub fn as_str(self) -> &'static str {
204        use IssuingPhysicalBundleFeaturesCarrierText::*;
205        match self {
206            Optional => "optional",
207            Required => "required",
208            Unsupported => "unsupported",
209        }
210    }
211}
212
213impl std::str::FromStr for IssuingPhysicalBundleFeaturesCarrierText {
214    type Err = stripe_types::StripeParseError;
215    fn from_str(s: &str) -> Result<Self, Self::Err> {
216        use IssuingPhysicalBundleFeaturesCarrierText::*;
217        match s {
218            "optional" => Ok(Optional),
219            "required" => Ok(Required),
220            "unsupported" => Ok(Unsupported),
221            _ => Err(stripe_types::StripeParseError),
222        }
223    }
224}
225impl std::fmt::Display for IssuingPhysicalBundleFeaturesCarrierText {
226    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
227        f.write_str(self.as_str())
228    }
229}
230
231impl std::fmt::Debug for IssuingPhysicalBundleFeaturesCarrierText {
232    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
233        f.write_str(self.as_str())
234    }
235}
236#[cfg(feature = "serialize")]
237impl serde::Serialize for IssuingPhysicalBundleFeaturesCarrierText {
238    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
239    where
240        S: serde::Serializer,
241    {
242        serializer.serialize_str(self.as_str())
243    }
244}
245impl miniserde::Deserialize for IssuingPhysicalBundleFeaturesCarrierText {
246    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
247        crate::Place::new(out)
248    }
249}
250
251impl miniserde::de::Visitor for crate::Place<IssuingPhysicalBundleFeaturesCarrierText> {
252    fn string(&mut self, s: &str) -> miniserde::Result<()> {
253        use std::str::FromStr;
254        self.out = Some(
255            IssuingPhysicalBundleFeaturesCarrierText::from_str(s).map_err(|_| miniserde::Error)?,
256        );
257        Ok(())
258    }
259}
260
261stripe_types::impl_from_val_with_from_str!(IssuingPhysicalBundleFeaturesCarrierText);
262#[cfg(feature = "deserialize")]
263impl<'de> serde::Deserialize<'de> for IssuingPhysicalBundleFeaturesCarrierText {
264    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
265        use std::str::FromStr;
266        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
267        Self::from_str(&s).map_err(|_| {
268            serde::de::Error::custom("Unknown value for IssuingPhysicalBundleFeaturesCarrierText")
269        })
270    }
271}
272/// The policy for how to use a second line on a card with this physical bundle.
273#[derive(Copy, Clone, Eq, PartialEq)]
274pub enum IssuingPhysicalBundleFeaturesSecondLine {
275    Optional,
276    Required,
277    Unsupported,
278}
279impl IssuingPhysicalBundleFeaturesSecondLine {
280    pub fn as_str(self) -> &'static str {
281        use IssuingPhysicalBundleFeaturesSecondLine::*;
282        match self {
283            Optional => "optional",
284            Required => "required",
285            Unsupported => "unsupported",
286        }
287    }
288}
289
290impl std::str::FromStr for IssuingPhysicalBundleFeaturesSecondLine {
291    type Err = stripe_types::StripeParseError;
292    fn from_str(s: &str) -> Result<Self, Self::Err> {
293        use IssuingPhysicalBundleFeaturesSecondLine::*;
294        match s {
295            "optional" => Ok(Optional),
296            "required" => Ok(Required),
297            "unsupported" => Ok(Unsupported),
298            _ => Err(stripe_types::StripeParseError),
299        }
300    }
301}
302impl std::fmt::Display for IssuingPhysicalBundleFeaturesSecondLine {
303    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
304        f.write_str(self.as_str())
305    }
306}
307
308impl std::fmt::Debug for IssuingPhysicalBundleFeaturesSecondLine {
309    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
310        f.write_str(self.as_str())
311    }
312}
313#[cfg(feature = "serialize")]
314impl serde::Serialize for IssuingPhysicalBundleFeaturesSecondLine {
315    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
316    where
317        S: serde::Serializer,
318    {
319        serializer.serialize_str(self.as_str())
320    }
321}
322impl miniserde::Deserialize for IssuingPhysicalBundleFeaturesSecondLine {
323    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
324        crate::Place::new(out)
325    }
326}
327
328impl miniserde::de::Visitor for crate::Place<IssuingPhysicalBundleFeaturesSecondLine> {
329    fn string(&mut self, s: &str) -> miniserde::Result<()> {
330        use std::str::FromStr;
331        self.out = Some(
332            IssuingPhysicalBundleFeaturesSecondLine::from_str(s).map_err(|_| miniserde::Error)?,
333        );
334        Ok(())
335    }
336}
337
338stripe_types::impl_from_val_with_from_str!(IssuingPhysicalBundleFeaturesSecondLine);
339#[cfg(feature = "deserialize")]
340impl<'de> serde::Deserialize<'de> for IssuingPhysicalBundleFeaturesSecondLine {
341    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
342        use std::str::FromStr;
343        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
344        Self::from_str(&s).map_err(|_| {
345            serde::de::Error::custom("Unknown value for IssuingPhysicalBundleFeaturesSecondLine")
346        })
347    }
348}