Skip to main content

stripe_shared/
issuing_transaction_receipt_data.rs

1#[derive(Clone)]
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 IssuingTransactionReceiptData {
6    /// The description of the item. The maximum length of this field is 26 characters.
7    pub description: Option<String>,
8    /// The quantity of the item.
9    pub quantity: Option<f64>,
10    /// The total for this line item in cents.
11    pub total: Option<i64>,
12    /// The unit cost of the item in cents.
13    pub unit_cost: Option<i64>,
14}
15#[cfg(feature = "redact-generated-debug")]
16impl std::fmt::Debug for IssuingTransactionReceiptData {
17    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
18        f.debug_struct("IssuingTransactionReceiptData").finish_non_exhaustive()
19    }
20}
21#[doc(hidden)]
22pub struct IssuingTransactionReceiptDataBuilder {
23    description: Option<Option<String>>,
24    quantity: Option<Option<f64>>,
25    total: Option<Option<i64>>,
26    unit_cost: Option<Option<i64>>,
27}
28
29#[allow(
30    unused_variables,
31    irrefutable_let_patterns,
32    clippy::let_unit_value,
33    clippy::match_single_binding,
34    clippy::single_match
35)]
36const _: () = {
37    use miniserde::de::{Map, Visitor};
38    use miniserde::json::Value;
39    use miniserde::{Deserialize, Result, make_place};
40    use stripe_types::miniserde_helpers::FromValueOpt;
41    use stripe_types::{MapBuilder, ObjectDeser};
42
43    make_place!(Place);
44
45    impl Deserialize for IssuingTransactionReceiptData {
46        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
47            Place::new(out)
48        }
49    }
50
51    struct Builder<'a> {
52        out: &'a mut Option<IssuingTransactionReceiptData>,
53        builder: IssuingTransactionReceiptDataBuilder,
54    }
55
56    impl Visitor for Place<IssuingTransactionReceiptData> {
57        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
58            Ok(Box::new(Builder {
59                out: &mut self.out,
60                builder: IssuingTransactionReceiptDataBuilder::deser_default(),
61            }))
62        }
63    }
64
65    impl MapBuilder for IssuingTransactionReceiptDataBuilder {
66        type Out = IssuingTransactionReceiptData;
67        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
68            Ok(match k {
69                "description" => Deserialize::begin(&mut self.description),
70                "quantity" => Deserialize::begin(&mut self.quantity),
71                "total" => Deserialize::begin(&mut self.total),
72                "unit_cost" => Deserialize::begin(&mut self.unit_cost),
73                _ => <dyn Visitor>::ignore(),
74            })
75        }
76
77        fn deser_default() -> Self {
78            Self {
79                description: Some(None),
80                quantity: Some(None),
81                total: Some(None),
82                unit_cost: Some(None),
83            }
84        }
85
86        fn take_out(&mut self) -> Option<Self::Out> {
87            let (Some(description), Some(quantity), Some(total), Some(unit_cost)) =
88                (self.description.take(), self.quantity, self.total, self.unit_cost)
89            else {
90                return None;
91            };
92            Some(Self::Out { description, quantity, total, unit_cost })
93        }
94    }
95
96    impl Map for Builder<'_> {
97        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
98            self.builder.key(k)
99        }
100
101        fn finish(&mut self) -> Result<()> {
102            *self.out = self.builder.take_out();
103            Ok(())
104        }
105    }
106
107    impl ObjectDeser for IssuingTransactionReceiptData {
108        type Builder = IssuingTransactionReceiptDataBuilder;
109    }
110
111    impl FromValueOpt for IssuingTransactionReceiptData {
112        fn from_value(v: Value) -> Option<Self> {
113            let Value::Object(obj) = v else {
114                return None;
115            };
116            let mut b = IssuingTransactionReceiptDataBuilder::deser_default();
117            for (k, v) in obj {
118                match k.as_str() {
119                    "description" => b.description = FromValueOpt::from_value(v),
120                    "quantity" => b.quantity = FromValueOpt::from_value(v),
121                    "total" => b.total = FromValueOpt::from_value(v),
122                    "unit_cost" => b.unit_cost = FromValueOpt::from_value(v),
123                    _ => {}
124                }
125            }
126            b.take_out()
127        }
128    }
129};