stripe_shared/
payment_links_resource_custom_fields_label.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentLinksResourceCustomFieldsLabel {
5    /// Custom text for the label, displayed to the customer. Up to 50 characters.
6    pub custom: Option<String>,
7    /// The type of the label.
8    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
9    pub type_: PaymentLinksResourceCustomFieldsLabelType,
10}
11#[doc(hidden)]
12pub struct PaymentLinksResourceCustomFieldsLabelBuilder {
13    custom: Option<Option<String>>,
14    type_: Option<PaymentLinksResourceCustomFieldsLabelType>,
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::{make_place, Deserialize, Result};
28    use stripe_types::miniserde_helpers::FromValueOpt;
29    use stripe_types::{MapBuilder, ObjectDeser};
30
31    make_place!(Place);
32
33    impl Deserialize for PaymentLinksResourceCustomFieldsLabel {
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<PaymentLinksResourceCustomFieldsLabel>,
41        builder: PaymentLinksResourceCustomFieldsLabelBuilder,
42    }
43
44    impl Visitor for Place<PaymentLinksResourceCustomFieldsLabel> {
45        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
46            Ok(Box::new(Builder {
47                out: &mut self.out,
48                builder: PaymentLinksResourceCustomFieldsLabelBuilder::deser_default(),
49            }))
50        }
51    }
52
53    impl MapBuilder for PaymentLinksResourceCustomFieldsLabelBuilder {
54        type Out = PaymentLinksResourceCustomFieldsLabel;
55        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
56            Ok(match k {
57                "custom" => Deserialize::begin(&mut self.custom),
58                "type" => Deserialize::begin(&mut self.type_),
59
60                _ => <dyn Visitor>::ignore(),
61            })
62        }
63
64        fn deser_default() -> Self {
65            Self { custom: Deserialize::default(), type_: Deserialize::default() }
66        }
67
68        fn take_out(&mut self) -> Option<Self::Out> {
69            let (Some(custom), Some(type_)) = (self.custom.take(), self.type_) else {
70                return None;
71            };
72            Some(Self::Out { custom, type_ })
73        }
74    }
75
76    impl<'a> Map for Builder<'a> {
77        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
78            self.builder.key(k)
79        }
80
81        fn finish(&mut self) -> Result<()> {
82            *self.out = self.builder.take_out();
83            Ok(())
84        }
85    }
86
87    impl ObjectDeser for PaymentLinksResourceCustomFieldsLabel {
88        type Builder = PaymentLinksResourceCustomFieldsLabelBuilder;
89    }
90
91    impl FromValueOpt for PaymentLinksResourceCustomFieldsLabel {
92        fn from_value(v: Value) -> Option<Self> {
93            let Value::Object(obj) = v else {
94                return None;
95            };
96            let mut b = PaymentLinksResourceCustomFieldsLabelBuilder::deser_default();
97            for (k, v) in obj {
98                match k.as_str() {
99                    "custom" => b.custom = FromValueOpt::from_value(v),
100                    "type" => b.type_ = FromValueOpt::from_value(v),
101
102                    _ => {}
103                }
104            }
105            b.take_out()
106        }
107    }
108};
109/// The type of the label.
110#[derive(Copy, Clone, Eq, PartialEq)]
111pub enum PaymentLinksResourceCustomFieldsLabelType {
112    Custom,
113}
114impl PaymentLinksResourceCustomFieldsLabelType {
115    pub fn as_str(self) -> &'static str {
116        use PaymentLinksResourceCustomFieldsLabelType::*;
117        match self {
118            Custom => "custom",
119        }
120    }
121}
122
123impl std::str::FromStr for PaymentLinksResourceCustomFieldsLabelType {
124    type Err = stripe_types::StripeParseError;
125    fn from_str(s: &str) -> Result<Self, Self::Err> {
126        use PaymentLinksResourceCustomFieldsLabelType::*;
127        match s {
128            "custom" => Ok(Custom),
129            _ => Err(stripe_types::StripeParseError),
130        }
131    }
132}
133impl std::fmt::Display for PaymentLinksResourceCustomFieldsLabelType {
134    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
135        f.write_str(self.as_str())
136    }
137}
138
139impl std::fmt::Debug for PaymentLinksResourceCustomFieldsLabelType {
140    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
141        f.write_str(self.as_str())
142    }
143}
144#[cfg(feature = "serialize")]
145impl serde::Serialize for PaymentLinksResourceCustomFieldsLabelType {
146    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
147    where
148        S: serde::Serializer,
149    {
150        serializer.serialize_str(self.as_str())
151    }
152}
153impl miniserde::Deserialize for PaymentLinksResourceCustomFieldsLabelType {
154    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
155        crate::Place::new(out)
156    }
157}
158
159impl miniserde::de::Visitor for crate::Place<PaymentLinksResourceCustomFieldsLabelType> {
160    fn string(&mut self, s: &str) -> miniserde::Result<()> {
161        use std::str::FromStr;
162        self.out = Some(
163            PaymentLinksResourceCustomFieldsLabelType::from_str(s).map_err(|_| miniserde::Error)?,
164        );
165        Ok(())
166    }
167}
168
169stripe_types::impl_from_val_with_from_str!(PaymentLinksResourceCustomFieldsLabelType);
170#[cfg(feature = "deserialize")]
171impl<'de> serde::Deserialize<'de> for PaymentLinksResourceCustomFieldsLabelType {
172    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
173        use std::str::FromStr;
174        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
175        Self::from_str(&s).map_err(|_| {
176            serde::de::Error::custom("Unknown value for PaymentLinksResourceCustomFieldsLabelType")
177        })
178    }
179}