Skip to main content

stripe_shared/
line_items_discount_amount.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 LineItemsDiscountAmount {
6    /// The amount discounted.
7    pub amount: i64,
8    pub discount: stripe_shared::Discount,
9}
10#[cfg(feature = "redact-generated-debug")]
11impl std::fmt::Debug for LineItemsDiscountAmount {
12    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
13        f.debug_struct("LineItemsDiscountAmount").finish_non_exhaustive()
14    }
15}
16#[doc(hidden)]
17pub struct LineItemsDiscountAmountBuilder {
18    amount: Option<i64>,
19    discount: Option<stripe_shared::Discount>,
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 LineItemsDiscountAmount {
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<LineItemsDiscountAmount>,
46        builder: LineItemsDiscountAmountBuilder,
47    }
48
49    impl Visitor for Place<LineItemsDiscountAmount> {
50        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
51            Ok(Box::new(Builder {
52                out: &mut self.out,
53                builder: LineItemsDiscountAmountBuilder::deser_default(),
54            }))
55        }
56    }
57
58    impl MapBuilder for LineItemsDiscountAmountBuilder {
59        type Out = LineItemsDiscountAmount;
60        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
61            Ok(match k {
62                "amount" => Deserialize::begin(&mut self.amount),
63                "discount" => Deserialize::begin(&mut self.discount),
64                _ => <dyn Visitor>::ignore(),
65            })
66        }
67
68        fn deser_default() -> Self {
69            Self { amount: None, discount: None }
70        }
71
72        fn take_out(&mut self) -> Option<Self::Out> {
73            let (Some(amount), Some(discount)) = (self.amount, self.discount.take()) else {
74                return None;
75            };
76            Some(Self::Out { amount, discount })
77        }
78    }
79
80    impl Map for Builder<'_> {
81        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
82            self.builder.key(k)
83        }
84
85        fn finish(&mut self) -> Result<()> {
86            *self.out = self.builder.take_out();
87            Ok(())
88        }
89    }
90
91    impl ObjectDeser for LineItemsDiscountAmount {
92        type Builder = LineItemsDiscountAmountBuilder;
93    }
94
95    impl FromValueOpt for LineItemsDiscountAmount {
96        fn from_value(v: Value) -> Option<Self> {
97            let Value::Object(obj) = v else {
98                return None;
99            };
100            let mut b = LineItemsDiscountAmountBuilder::deser_default();
101            for (k, v) in obj {
102                match k.as_str() {
103                    "amount" => b.amount = FromValueOpt::from_value(v),
104                    "discount" => b.discount = FromValueOpt::from_value(v),
105                    _ => {}
106                }
107            }
108            b.take_out()
109        }
110    }
111};