Skip to main content

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