stripe_shared/
payment_flows_amount_details_resource_shipping.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentFlowsAmountDetailsResourceShipping {
5    /// If a physical good is being shipped, the cost of shipping represented in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal).
6    /// An integer greater than or equal to 0.
7    pub amount: Option<i64>,
8    /// If a physical good is being shipped, the postal code of where it is being shipped from.
9    /// At most 10 alphanumeric characters long, hyphens are allowed.
10    pub from_postal_code: Option<String>,
11    /// If a physical good is being shipped, the postal code of where it is being shipped to.
12    /// At most 10 alphanumeric characters long, hyphens are allowed.
13    pub to_postal_code: Option<String>,
14}
15#[doc(hidden)]
16pub struct PaymentFlowsAmountDetailsResourceShippingBuilder {
17    amount: Option<Option<i64>>,
18    from_postal_code: Option<Option<String>>,
19    to_postal_code: Option<Option<String>>,
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 PaymentFlowsAmountDetailsResourceShipping {
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<PaymentFlowsAmountDetailsResourceShipping>,
46        builder: PaymentFlowsAmountDetailsResourceShippingBuilder,
47    }
48
49    impl Visitor for Place<PaymentFlowsAmountDetailsResourceShipping> {
50        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
51            Ok(Box::new(Builder {
52                out: &mut self.out,
53                builder: PaymentFlowsAmountDetailsResourceShippingBuilder::deser_default(),
54            }))
55        }
56    }
57
58    impl MapBuilder for PaymentFlowsAmountDetailsResourceShippingBuilder {
59        type Out = PaymentFlowsAmountDetailsResourceShipping;
60        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
61            Ok(match k {
62                "amount" => Deserialize::begin(&mut self.amount),
63                "from_postal_code" => Deserialize::begin(&mut self.from_postal_code),
64                "to_postal_code" => Deserialize::begin(&mut self.to_postal_code),
65                _ => <dyn Visitor>::ignore(),
66            })
67        }
68
69        fn deser_default() -> Self {
70            Self {
71                amount: Deserialize::default(),
72                from_postal_code: Deserialize::default(),
73                to_postal_code: Deserialize::default(),
74            }
75        }
76
77        fn take_out(&mut self) -> Option<Self::Out> {
78            let (Some(amount), Some(from_postal_code), Some(to_postal_code)) =
79                (self.amount, self.from_postal_code.take(), self.to_postal_code.take())
80            else {
81                return None;
82            };
83            Some(Self::Out { amount, from_postal_code, to_postal_code })
84        }
85    }
86
87    impl Map for Builder<'_> {
88        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
89            self.builder.key(k)
90        }
91
92        fn finish(&mut self) -> Result<()> {
93            *self.out = self.builder.take_out();
94            Ok(())
95        }
96    }
97
98    impl ObjectDeser for PaymentFlowsAmountDetailsResourceShipping {
99        type Builder = PaymentFlowsAmountDetailsResourceShippingBuilder;
100    }
101
102    impl FromValueOpt for PaymentFlowsAmountDetailsResourceShipping {
103        fn from_value(v: Value) -> Option<Self> {
104            let Value::Object(obj) = v else {
105                return None;
106            };
107            let mut b = PaymentFlowsAmountDetailsResourceShippingBuilder::deser_default();
108            for (k, v) in obj {
109                match k.as_str() {
110                    "amount" => b.amount = FromValueOpt::from_value(v),
111                    "from_postal_code" => b.from_postal_code = FromValueOpt::from_value(v),
112                    "to_postal_code" => b.to_postal_code = FromValueOpt::from_value(v),
113                    _ => {}
114                }
115            }
116            b.take_out()
117        }
118    }
119};