stripe_shared/
payment_links_resource_custom_fields_dropdown_option.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentLinksResourceCustomFieldsDropdownOption {
5    /// The label for the option, displayed to the customer. Up to 100 characters.
6    pub label: String,
7    /// The value for this option, not displayed to the customer, used by your integration to reconcile the option selected by the customer.
8    /// Must be unique to this option, alphanumeric, and up to 100 characters.
9    pub value: String,
10}
11#[doc(hidden)]
12pub struct PaymentLinksResourceCustomFieldsDropdownOptionBuilder {
13    label: Option<String>,
14    value: Option<String>,
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 PaymentLinksResourceCustomFieldsDropdownOption {
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<PaymentLinksResourceCustomFieldsDropdownOption>,
41        builder: PaymentLinksResourceCustomFieldsDropdownOptionBuilder,
42    }
43
44    impl Visitor for Place<PaymentLinksResourceCustomFieldsDropdownOption> {
45        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
46            Ok(Box::new(Builder {
47                out: &mut self.out,
48                builder: PaymentLinksResourceCustomFieldsDropdownOptionBuilder::deser_default(),
49            }))
50        }
51    }
52
53    impl MapBuilder for PaymentLinksResourceCustomFieldsDropdownOptionBuilder {
54        type Out = PaymentLinksResourceCustomFieldsDropdownOption;
55        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
56            Ok(match k {
57                "label" => Deserialize::begin(&mut self.label),
58                "value" => Deserialize::begin(&mut self.value),
59
60                _ => <dyn Visitor>::ignore(),
61            })
62        }
63
64        fn deser_default() -> Self {
65            Self { label: Deserialize::default(), value: Deserialize::default() }
66        }
67
68        fn take_out(&mut self) -> Option<Self::Out> {
69            let (Some(label), Some(value)) = (self.label.take(), self.value.take()) else {
70                return None;
71            };
72            Some(Self::Out { label, value })
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 PaymentLinksResourceCustomFieldsDropdownOption {
88        type Builder = PaymentLinksResourceCustomFieldsDropdownOptionBuilder;
89    }
90
91    impl FromValueOpt for PaymentLinksResourceCustomFieldsDropdownOption {
92        fn from_value(v: Value) -> Option<Self> {
93            let Value::Object(obj) = v else {
94                return None;
95            };
96            let mut b = PaymentLinksResourceCustomFieldsDropdownOptionBuilder::deser_default();
97            for (k, v) in obj {
98                match k.as_str() {
99                    "label" => b.label = FromValueOpt::from_value(v),
100                    "value" => b.value = FromValueOpt::from_value(v),
101
102                    _ => {}
103                }
104            }
105            b.take_out()
106        }
107    }
108};