stripe_shared/
level3_line_items.rs1#[derive(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 Level3LineItems {
6 pub discount_amount: Option<i64>,
7 pub product_code: String,
8 pub product_description: String,
9 pub quantity: Option<u64>,
10 pub tax_amount: Option<i64>,
11 pub unit_cost: Option<i64>,
12}
13#[cfg(feature = "redact-generated-debug")]
14impl std::fmt::Debug for Level3LineItems {
15 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
16 f.debug_struct("Level3LineItems").finish_non_exhaustive()
17 }
18}
19#[doc(hidden)]
20pub struct Level3LineItemsBuilder {
21 discount_amount: Option<Option<i64>>,
22 product_code: Option<String>,
23 product_description: Option<String>,
24 quantity: Option<Option<u64>>,
25 tax_amount: 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 Level3LineItems {
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<Level3LineItems>,
53 builder: Level3LineItemsBuilder,
54 }
55
56 impl Visitor for Place<Level3LineItems> {
57 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
58 Ok(Box::new(Builder {
59 out: &mut self.out,
60 builder: Level3LineItemsBuilder::deser_default(),
61 }))
62 }
63 }
64
65 impl MapBuilder for Level3LineItemsBuilder {
66 type Out = Level3LineItems;
67 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
68 Ok(match k {
69 "discount_amount" => Deserialize::begin(&mut self.discount_amount),
70 "product_code" => Deserialize::begin(&mut self.product_code),
71 "product_description" => Deserialize::begin(&mut self.product_description),
72 "quantity" => Deserialize::begin(&mut self.quantity),
73 "tax_amount" => Deserialize::begin(&mut self.tax_amount),
74 "unit_cost" => Deserialize::begin(&mut self.unit_cost),
75 _ => <dyn Visitor>::ignore(),
76 })
77 }
78
79 fn deser_default() -> Self {
80 Self {
81 discount_amount: Some(None),
82 product_code: None,
83 product_description: None,
84 quantity: Some(None),
85 tax_amount: Some(None),
86 unit_cost: Some(None),
87 }
88 }
89
90 fn take_out(&mut self) -> Option<Self::Out> {
91 let (
92 Some(discount_amount),
93 Some(product_code),
94 Some(product_description),
95 Some(quantity),
96 Some(tax_amount),
97 Some(unit_cost),
98 ) = (
99 self.discount_amount,
100 self.product_code.take(),
101 self.product_description.take(),
102 self.quantity,
103 self.tax_amount,
104 self.unit_cost,
105 )
106 else {
107 return None;
108 };
109 Some(Self::Out {
110 discount_amount,
111 product_code,
112 product_description,
113 quantity,
114 tax_amount,
115 unit_cost,
116 })
117 }
118 }
119
120 impl Map for Builder<'_> {
121 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
122 self.builder.key(k)
123 }
124
125 fn finish(&mut self) -> Result<()> {
126 *self.out = self.builder.take_out();
127 Ok(())
128 }
129 }
130
131 impl ObjectDeser for Level3LineItems {
132 type Builder = Level3LineItemsBuilder;
133 }
134
135 impl FromValueOpt for Level3LineItems {
136 fn from_value(v: Value) -> Option<Self> {
137 let Value::Object(obj) = v else {
138 return None;
139 };
140 let mut b = Level3LineItemsBuilder::deser_default();
141 for (k, v) in obj {
142 match k.as_str() {
143 "discount_amount" => b.discount_amount = FromValueOpt::from_value(v),
144 "product_code" => b.product_code = FromValueOpt::from_value(v),
145 "product_description" => b.product_description = FromValueOpt::from_value(v),
146 "quantity" => b.quantity = FromValueOpt::from_value(v),
147 "tax_amount" => b.tax_amount = FromValueOpt::from_value(v),
148 "unit_cost" => b.unit_cost = FromValueOpt::from_value(v),
149 _ => {}
150 }
151 }
152 b.take_out()
153 }
154 }
155};