Skip to main content

stripe_shared/
invoice_setting_custom_field.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 InvoiceSettingCustomField {
6    /// The name of the custom field.
7    pub name: String,
8    /// The value of the custom field.
9    pub value: String,
10}
11#[cfg(feature = "redact-generated-debug")]
12impl std::fmt::Debug for InvoiceSettingCustomField {
13    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
14        f.debug_struct("InvoiceSettingCustomField").finish_non_exhaustive()
15    }
16}
17#[doc(hidden)]
18pub struct InvoiceSettingCustomFieldBuilder {
19    name: Option<String>,
20    value: Option<String>,
21}
22
23#[allow(
24    unused_variables,
25    irrefutable_let_patterns,
26    clippy::let_unit_value,
27    clippy::match_single_binding,
28    clippy::single_match
29)]
30const _: () = {
31    use miniserde::de::{Map, Visitor};
32    use miniserde::json::Value;
33    use miniserde::{Deserialize, Result, make_place};
34    use stripe_types::miniserde_helpers::FromValueOpt;
35    use stripe_types::{MapBuilder, ObjectDeser};
36
37    make_place!(Place);
38
39    impl Deserialize for InvoiceSettingCustomField {
40        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
41            Place::new(out)
42        }
43    }
44
45    struct Builder<'a> {
46        out: &'a mut Option<InvoiceSettingCustomField>,
47        builder: InvoiceSettingCustomFieldBuilder,
48    }
49
50    impl Visitor for Place<InvoiceSettingCustomField> {
51        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
52            Ok(Box::new(Builder {
53                out: &mut self.out,
54                builder: InvoiceSettingCustomFieldBuilder::deser_default(),
55            }))
56        }
57    }
58
59    impl MapBuilder for InvoiceSettingCustomFieldBuilder {
60        type Out = InvoiceSettingCustomField;
61        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
62            Ok(match k {
63                "name" => Deserialize::begin(&mut self.name),
64                "value" => Deserialize::begin(&mut self.value),
65                _ => <dyn Visitor>::ignore(),
66            })
67        }
68
69        fn deser_default() -> Self {
70            Self { name: None, value: None }
71        }
72
73        fn take_out(&mut self) -> Option<Self::Out> {
74            let (Some(name), Some(value)) = (self.name.take(), self.value.take()) else {
75                return None;
76            };
77            Some(Self::Out { name, value })
78        }
79    }
80
81    impl Map for Builder<'_> {
82        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
83            self.builder.key(k)
84        }
85
86        fn finish(&mut self) -> Result<()> {
87            *self.out = self.builder.take_out();
88            Ok(())
89        }
90    }
91
92    impl ObjectDeser for InvoiceSettingCustomField {
93        type Builder = InvoiceSettingCustomFieldBuilder;
94    }
95
96    impl FromValueOpt for InvoiceSettingCustomField {
97        fn from_value(v: Value) -> Option<Self> {
98            let Value::Object(obj) = v else {
99                return None;
100            };
101            let mut b = InvoiceSettingCustomFieldBuilder::deser_default();
102            for (k, v) in obj {
103                match k.as_str() {
104                    "name" => b.name = FromValueOpt::from_value(v),
105                    "value" => b.value = FromValueOpt::from_value(v),
106                    _ => {}
107                }
108            }
109            b.take_out()
110        }
111    }
112};