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::{Deserialize, Result, make_place};
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                _ => <dyn Visitor>::ignore(),
59            })
60        }
61
62        fn deser_default() -> Self {
63            Self { check_in_at: Deserialize::default(), nights: Deserialize::default() }
64        }
65
66        fn take_out(&mut self) -> Option<Self::Out> {
67            let (Some(check_in_at), Some(nights)) = (self.check_in_at, self.nights) else {
68                return None;
69            };
70            Some(Self::Out { check_in_at, nights })
71        }
72    }
73
74    impl Map for Builder<'_> {
75        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
76            self.builder.key(k)
77        }
78
79        fn finish(&mut self) -> Result<()> {
80            *self.out = self.builder.take_out();
81            Ok(())
82        }
83    }
84
85    impl ObjectDeser for IssuingTransactionLodgingData {
86        type Builder = IssuingTransactionLodgingDataBuilder;
87    }
88
89    impl FromValueOpt for IssuingTransactionLodgingData {
90        fn from_value(v: Value) -> Option<Self> {
91            let Value::Object(obj) = v else {
92                return None;
93            };
94            let mut b = IssuingTransactionLodgingDataBuilder::deser_default();
95            for (k, v) in obj {
96                match k.as_str() {
97                    "check_in_at" => b.check_in_at = FromValueOpt::from_value(v),
98                    "nights" => b.nights = FromValueOpt::from_value(v),
99                    _ => {}
100                }
101            }
102            b.take_out()
103        }
104    }
105};