stripe_shared/
legal_entity_registration_date.rs

1#[derive(Copy, Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct LegalEntityRegistrationDate {
5    /// The day of registration, between 1 and 31.
6    pub day: Option<i64>,
7    /// The month of registration, between 1 and 12.
8    pub month: Option<i64>,
9    /// The four-digit year of registration.
10    pub year: Option<i64>,
11}
12#[doc(hidden)]
13pub struct LegalEntityRegistrationDateBuilder {
14    day: Option<Option<i64>>,
15    month: Option<Option<i64>>,
16    year: Option<Option<i64>>,
17}
18
19#[allow(
20    unused_variables,
21    irrefutable_let_patterns,
22    clippy::let_unit_value,
23    clippy::match_single_binding,
24    clippy::single_match
25)]
26const _: () = {
27    use miniserde::de::{Map, Visitor};
28    use miniserde::json::Value;
29    use miniserde::{Deserialize, Result, make_place};
30    use stripe_types::miniserde_helpers::FromValueOpt;
31    use stripe_types::{MapBuilder, ObjectDeser};
32
33    make_place!(Place);
34
35    impl Deserialize for LegalEntityRegistrationDate {
36        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
37            Place::new(out)
38        }
39    }
40
41    struct Builder<'a> {
42        out: &'a mut Option<LegalEntityRegistrationDate>,
43        builder: LegalEntityRegistrationDateBuilder,
44    }
45
46    impl Visitor for Place<LegalEntityRegistrationDate> {
47        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
48            Ok(Box::new(Builder {
49                out: &mut self.out,
50                builder: LegalEntityRegistrationDateBuilder::deser_default(),
51            }))
52        }
53    }
54
55    impl MapBuilder for LegalEntityRegistrationDateBuilder {
56        type Out = LegalEntityRegistrationDate;
57        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
58            Ok(match k {
59                "day" => Deserialize::begin(&mut self.day),
60                "month" => Deserialize::begin(&mut self.month),
61                "year" => Deserialize::begin(&mut self.year),
62                _ => <dyn Visitor>::ignore(),
63            })
64        }
65
66        fn deser_default() -> Self {
67            Self {
68                day: Deserialize::default(),
69                month: Deserialize::default(),
70                year: Deserialize::default(),
71            }
72        }
73
74        fn take_out(&mut self) -> Option<Self::Out> {
75            let (Some(day), Some(month), Some(year)) = (self.day, self.month, self.year) else {
76                return None;
77            };
78            Some(Self::Out { day, month, year })
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 LegalEntityRegistrationDate {
94        type Builder = LegalEntityRegistrationDateBuilder;
95    }
96
97    impl FromValueOpt for LegalEntityRegistrationDate {
98        fn from_value(v: Value) -> Option<Self> {
99            let Value::Object(obj) = v else {
100                return None;
101            };
102            let mut b = LegalEntityRegistrationDateBuilder::deser_default();
103            for (k, v) in obj {
104                match k.as_str() {
105                    "day" => b.day = FromValueOpt::from_value(v),
106                    "month" => b.month = FromValueOpt::from_value(v),
107                    "year" => b.year = FromValueOpt::from_value(v),
108                    _ => {}
109                }
110            }
111            b.take_out()
112        }
113    }
114};