Skip to main content

stripe_shared/
payment_pages_checkout_session_custom_fields_label.rs

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