stripe_shared/
level3_line_items.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct Level3LineItems {
5    pub discount_amount: Option<i64>,
6    pub product_code: String,
7    pub product_description: String,
8    pub quantity: Option<u64>,
9    pub tax_amount: Option<i64>,
10    pub unit_cost: Option<i64>,
11}
12#[doc(hidden)]
13pub struct Level3LineItemsBuilder {
14    discount_amount: Option<Option<i64>>,
15    product_code: Option<String>,
16    product_description: Option<String>,
17    quantity: Option<Option<u64>>,
18    tax_amount: Option<Option<i64>>,
19    unit_cost: Option<Option<i64>>,
20}
21
22#[allow(
23    unused_variables,
24    irrefutable_let_patterns,
25    clippy::let_unit_value,
26    clippy::match_single_binding,
27    clippy::single_match
28)]
29const _: () = {
30    use miniserde::de::{Map, Visitor};
31    use miniserde::json::Value;
32    use miniserde::{Deserialize, Result, make_place};
33    use stripe_types::miniserde_helpers::FromValueOpt;
34    use stripe_types::{MapBuilder, ObjectDeser};
35
36    make_place!(Place);
37
38    impl Deserialize for Level3LineItems {
39        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
40            Place::new(out)
41        }
42    }
43
44    struct Builder<'a> {
45        out: &'a mut Option<Level3LineItems>,
46        builder: Level3LineItemsBuilder,
47    }
48
49    impl Visitor for Place<Level3LineItems> {
50        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
51            Ok(Box::new(Builder {
52                out: &mut self.out,
53                builder: Level3LineItemsBuilder::deser_default(),
54            }))
55        }
56    }
57
58    impl MapBuilder for Level3LineItemsBuilder {
59        type Out = Level3LineItems;
60        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
61            Ok(match k {
62                "discount_amount" => Deserialize::begin(&mut self.discount_amount),
63                "product_code" => Deserialize::begin(&mut self.product_code),
64                "product_description" => Deserialize::begin(&mut self.product_description),
65                "quantity" => Deserialize::begin(&mut self.quantity),
66                "tax_amount" => Deserialize::begin(&mut self.tax_amount),
67                "unit_cost" => Deserialize::begin(&mut self.unit_cost),
68
69                _ => <dyn Visitor>::ignore(),
70            })
71        }
72
73        fn deser_default() -> Self {
74            Self {
75                discount_amount: Deserialize::default(),
76                product_code: Deserialize::default(),
77                product_description: Deserialize::default(),
78                quantity: Deserialize::default(),
79                tax_amount: Deserialize::default(),
80                unit_cost: Deserialize::default(),
81            }
82        }
83
84        fn take_out(&mut self) -> Option<Self::Out> {
85            let (
86                Some(discount_amount),
87                Some(product_code),
88                Some(product_description),
89                Some(quantity),
90                Some(tax_amount),
91                Some(unit_cost),
92            ) = (
93                self.discount_amount,
94                self.product_code.take(),
95                self.product_description.take(),
96                self.quantity,
97                self.tax_amount,
98                self.unit_cost,
99            )
100            else {
101                return None;
102            };
103            Some(Self::Out {
104                discount_amount,
105                product_code,
106                product_description,
107                quantity,
108                tax_amount,
109                unit_cost,
110            })
111        }
112    }
113
114    impl Map for Builder<'_> {
115        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
116            self.builder.key(k)
117        }
118
119        fn finish(&mut self) -> Result<()> {
120            *self.out = self.builder.take_out();
121            Ok(())
122        }
123    }
124
125    impl ObjectDeser for Level3LineItems {
126        type Builder = Level3LineItemsBuilder;
127    }
128
129    impl FromValueOpt for Level3LineItems {
130        fn from_value(v: Value) -> Option<Self> {
131            let Value::Object(obj) = v else {
132                return None;
133            };
134            let mut b = Level3LineItemsBuilder::deser_default();
135            for (k, v) in obj {
136                match k.as_str() {
137                    "discount_amount" => b.discount_amount = FromValueOpt::from_value(v),
138                    "product_code" => b.product_code = FromValueOpt::from_value(v),
139                    "product_description" => b.product_description = FromValueOpt::from_value(v),
140                    "quantity" => b.quantity = FromValueOpt::from_value(v),
141                    "tax_amount" => b.tax_amount = FromValueOpt::from_value(v),
142                    "unit_cost" => b.unit_cost = FromValueOpt::from_value(v),
143
144                    _ => {}
145                }
146            }
147            b.take_out()
148        }
149    }
150};