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                _ => <dyn Visitor>::ignore(),
77            })
78        }
79
80        fn deser_default() -> Self {
81            Self {
82                amount: Deserialize::default(),
83                currency: Deserialize::default(),
84                currency_options: Deserialize::default(),
85            }
86        }
87
88        fn take_out(&mut self) -> Option<Self::Out> {
89            let (Some(amount), Some(currency), Some(currency_options)) =
90                (self.amount, self.currency.take(), self.currency_options.take())
91            else {
92                return None;
93            };
94            Some(Self::Out { amount, currency, currency_options })
95        }
96    }
97
98    impl Map for Builder<'_> {
99        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
100            self.builder.key(k)
101        }
102
103        fn finish(&mut self) -> Result<()> {
104            *self.out = self.builder.take_out();
105            Ok(())
106        }
107    }
108
109    impl ObjectDeser for ShippingRateFixedAmount {
110        type Builder = ShippingRateFixedAmountBuilder;
111    }
112
113    impl FromValueOpt for ShippingRateFixedAmount {
114        fn from_value(v: Value) -> Option<Self> {
115            let Value::Object(obj) = v else {
116                return None;
117            };
118            let mut b = ShippingRateFixedAmountBuilder::deser_default();
119            for (k, v) in obj {
120                match k.as_str() {
121                    "amount" => b.amount = FromValueOpt::from_value(v),
122                    "currency" => b.currency = FromValueOpt::from_value(v),
123                    "currency_options" => b.currency_options = FromValueOpt::from_value(v),
124                    _ => {}
125                }
126            }
127            b.take_out()
128        }
129    }
130};