stripe_misc/
gelato_data_document_report_expiration_date.rs

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