stripe_shared/
shipping_rate_fixed_amount.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct ShippingRateFixedAmount {
5    /// A non-negative integer in cents representing how much to charge.
6    pub amount: i64,
7    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
8    /// Must be a [supported currency](https://stripe.com/docs/currencies).
9    pub currency: stripe_types::Currency,
10    /// Shipping rates defined in each available currency option.
11    /// Each key must be a three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html) and a [supported currency](https://stripe.com/docs/currencies).
12    pub currency_options: Option<
13        std::collections::HashMap<
14            stripe_types::Currency,
15            stripe_shared::ShippingRateCurrencyOption,
16        >,
17    >,
18}
19#[doc(hidden)]
20pub struct ShippingRateFixedAmountBuilder {
21    amount: Option<i64>,
22    currency: Option<stripe_types::Currency>,
23    currency_options: Option<
24        Option<
25            std::collections::HashMap<
26                stripe_types::Currency,
27                stripe_shared::ShippingRateCurrencyOption,
28            >,
29        >,
30    >,
31}
32
33#[allow(
34    unused_variables,
35    irrefutable_let_patterns,
36    clippy::let_unit_value,
37    clippy::match_single_binding,
38    clippy::single_match
39)]
40const _: () = {
41    use miniserde::de::{Map, Visitor};
42    use miniserde::json::Value;
43    use miniserde::{Deserialize, Result, make_place};
44    use stripe_types::miniserde_helpers::FromValueOpt;
45    use stripe_types::{MapBuilder, ObjectDeser};
46
47    make_place!(Place);
48
49    impl Deserialize for ShippingRateFixedAmount {
50        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
51            Place::new(out)
52        }
53    }
54
55    struct Builder<'a> {
56        out: &'a mut Option<ShippingRateFixedAmount>,
57        builder: ShippingRateFixedAmountBuilder,
58    }
59
60    impl Visitor for Place<ShippingRateFixedAmount> {
61        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
62            Ok(Box::new(Builder {
63                out: &mut self.out,
64                builder: ShippingRateFixedAmountBuilder::deser_default(),
65            }))
66        }
67    }
68
69    impl MapBuilder for ShippingRateFixedAmountBuilder {
70        type Out = ShippingRateFixedAmount;
71        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
72            Ok(match k {
73                "amount" => Deserialize::begin(&mut self.amount),
74                "currency" => Deserialize::begin(&mut self.currency),
75                "currency_options" => Deserialize::begin(&mut self.currency_options),
76
77                _ => <dyn Visitor>::ignore(),
78            })
79        }
80
81        fn deser_default() -> Self {
82            Self {
83                amount: Deserialize::default(),
84                currency: Deserialize::default(),
85                currency_options: Deserialize::default(),
86            }
87        }
88
89        fn take_out(&mut self) -> Option<Self::Out> {
90            let (Some(amount), Some(currency), Some(currency_options)) =
91                (self.amount, self.currency.take(), self.currency_options.take())
92            else {
93                return None;
94            };
95            Some(Self::Out { amount, currency, currency_options })
96        }
97    }
98
99    impl Map for Builder<'_> {
100        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
101            self.builder.key(k)
102        }
103
104        fn finish(&mut self) -> Result<()> {
105            *self.out = self.builder.take_out();
106            Ok(())
107        }
108    }
109
110    impl ObjectDeser for ShippingRateFixedAmount {
111        type Builder = ShippingRateFixedAmountBuilder;
112    }
113
114    impl FromValueOpt for ShippingRateFixedAmount {
115        fn from_value(v: Value) -> Option<Self> {
116            let Value::Object(obj) = v else {
117                return None;
118            };
119            let mut b = ShippingRateFixedAmountBuilder::deser_default();
120            for (k, v) in obj {
121                match k.as_str() {
122                    "amount" => b.amount = FromValueOpt::from_value(v),
123                    "currency" => b.currency = FromValueOpt::from_value(v),
124                    "currency_options" => b.currency_options = FromValueOpt::from_value(v),
125
126                    _ => {}
127                }
128            }
129            b.take_out()
130        }
131    }
132};