stripe_shared/
invoices_resource_shipping_cost.rs

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