Skip to main content

stripe_shared/
issuing_transaction_lodging_data.rs

1#[derive(Copy, 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 IssuingTransactionLodgingData {
6    /// The time of checking into the lodging.
7    pub check_in_at: Option<i64>,
8    /// The number of nights stayed at the lodging.
9    pub nights: Option<i64>,
10}
11#[cfg(feature = "redact-generated-debug")]
12impl std::fmt::Debug for IssuingTransactionLodgingData {
13    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
14        f.debug_struct("IssuingTransactionLodgingData").finish_non_exhaustive()
15    }
16}
17#[doc(hidden)]
18pub struct IssuingTransactionLodgingDataBuilder {
19    check_in_at: Option<Option<i64>>,
20    nights: Option<Option<i64>>,
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 IssuingTransactionLodgingData {
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<IssuingTransactionLodgingData>,
47        builder: IssuingTransactionLodgingDataBuilder,
48    }
49
50    impl Visitor for Place<IssuingTransactionLodgingData> {
51        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
52            Ok(Box::new(Builder {
53                out: &mut self.out,
54                builder: IssuingTransactionLodgingDataBuilder::deser_default(),
55            }))
56        }
57    }
58
59    impl MapBuilder for IssuingTransactionLodgingDataBuilder {
60        type Out = IssuingTransactionLodgingData;
61        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
62            Ok(match k {
63                "check_in_at" => Deserialize::begin(&mut self.check_in_at),
64                "nights" => Deserialize::begin(&mut self.nights),
65                _ => <dyn Visitor>::ignore(),
66            })
67        }
68
69        fn deser_default() -> Self {
70            Self { check_in_at: Some(None), nights: Some(None) }
71        }
72
73        fn take_out(&mut self) -> Option<Self::Out> {
74            let (Some(check_in_at), Some(nights)) = (self.check_in_at, self.nights) else {
75                return None;
76            };
77            Some(Self::Out { check_in_at, nights })
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 IssuingTransactionLodgingData {
93        type Builder = IssuingTransactionLodgingDataBuilder;
94    }
95
96    impl FromValueOpt for IssuingTransactionLodgingData {
97        fn from_value(v: Value) -> Option<Self> {
98            let Value::Object(obj) = v else {
99                return None;
100            };
101            let mut b = IssuingTransactionLodgingDataBuilder::deser_default();
102            for (k, v) in obj {
103                match k.as_str() {
104                    "check_in_at" => b.check_in_at = FromValueOpt::from_value(v),
105                    "nights" => b.nights = FromValueOpt::from_value(v),
106                    _ => {}
107                }
108            }
109            b.take_out()
110        }
111    }
112};