Skip to main content

stripe_shared/
payment_links_resource_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 PaymentLinksResourceCustomFieldsLabel {
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_: PaymentLinksResourceCustomFieldsLabelType,
11}
12#[cfg(feature = "redact-generated-debug")]
13impl std::fmt::Debug for PaymentLinksResourceCustomFieldsLabel {
14    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
15        f.debug_struct("PaymentLinksResourceCustomFieldsLabel").finish_non_exhaustive()
16    }
17}
18#[doc(hidden)]
19pub struct PaymentLinksResourceCustomFieldsLabelBuilder {
20    custom: Option<Option<String>>,
21    type_: Option<PaymentLinksResourceCustomFieldsLabelType>,
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 PaymentLinksResourceCustomFieldsLabel {
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<PaymentLinksResourceCustomFieldsLabel>,
48        builder: PaymentLinksResourceCustomFieldsLabelBuilder,
49    }
50
51    impl Visitor for Place<PaymentLinksResourceCustomFieldsLabel> {
52        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
53            Ok(Box::new(Builder {
54                out: &mut self.out,
55                builder: PaymentLinksResourceCustomFieldsLabelBuilder::deser_default(),
56            }))
57        }
58    }
59
60    impl MapBuilder for PaymentLinksResourceCustomFieldsLabelBuilder {
61        type Out = PaymentLinksResourceCustomFieldsLabel;
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 PaymentLinksResourceCustomFieldsLabel {
94        type Builder = PaymentLinksResourceCustomFieldsLabelBuilder;
95    }
96
97    impl FromValueOpt for PaymentLinksResourceCustomFieldsLabel {
98        fn from_value(v: Value) -> Option<Self> {
99            let Value::Object(obj) = v else {
100                return None;
101            };
102            let mut b = PaymentLinksResourceCustomFieldsLabelBuilder::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 PaymentLinksResourceCustomFieldsLabelType {
118    Custom,
119    /// An unrecognized value from Stripe. Should not be used as a request parameter.
120    Unknown(String),
121}
122impl PaymentLinksResourceCustomFieldsLabelType {
123    pub fn as_str(&self) -> &str {
124        use PaymentLinksResourceCustomFieldsLabelType::*;
125        match self {
126            Custom => "custom",
127            Unknown(v) => v,
128        }
129    }
130}
131
132impl std::str::FromStr for PaymentLinksResourceCustomFieldsLabelType {
133    type Err = std::convert::Infallible;
134    fn from_str(s: &str) -> Result<Self, Self::Err> {
135        use PaymentLinksResourceCustomFieldsLabelType::*;
136        match s {
137            "custom" => Ok(Custom),
138            v => {
139                tracing::warn!(
140                    "Unknown value '{}' for enum '{}'",
141                    v,
142                    "PaymentLinksResourceCustomFieldsLabelType"
143                );
144                Ok(Unknown(v.to_owned()))
145            }
146        }
147    }
148}
149impl std::fmt::Display for PaymentLinksResourceCustomFieldsLabelType {
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 PaymentLinksResourceCustomFieldsLabelType {
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 PaymentLinksResourceCustomFieldsLabelType {
163    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
164        f.debug_struct(stringify!(PaymentLinksResourceCustomFieldsLabelType))
165            .finish_non_exhaustive()
166    }
167}
168#[cfg(feature = "serialize")]
169impl serde::Serialize for PaymentLinksResourceCustomFieldsLabelType {
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 PaymentLinksResourceCustomFieldsLabelType {
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<PaymentLinksResourceCustomFieldsLabelType> {
184    fn string(&mut self, s: &str) -> miniserde::Result<()> {
185        use std::str::FromStr;
186        self.out =
187            Some(PaymentLinksResourceCustomFieldsLabelType::from_str(s).expect("infallible"));
188        Ok(())
189    }
190}
191
192stripe_types::impl_from_val_with_from_str!(PaymentLinksResourceCustomFieldsLabelType);
193#[cfg(feature = "deserialize")]
194impl<'de> serde::Deserialize<'de> for PaymentLinksResourceCustomFieldsLabelType {
195    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
196        use std::str::FromStr;
197        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
198        Ok(Self::from_str(&s).expect("infallible"))
199    }
200}