stripe_shared/
issuing_transaction_lodging_data.rs

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