stripe_misc/
climate_removals_products_price.rs

1#[derive(Copy, Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct ClimateRemovalsProductsPrice {
5    /// Fees for one metric ton of carbon removal in the currency's smallest unit.
6    pub amount_fees: i64,
7    /// Subtotal for one metric ton of carbon removal (excluding fees) in the currency's smallest unit.
8    pub amount_subtotal: i64,
9    /// Total for one metric ton of carbon removal (including fees) in the currency's smallest unit.
10    pub amount_total: i64,
11}
12#[doc(hidden)]
13pub struct ClimateRemovalsProductsPriceBuilder {
14    amount_fees: Option<i64>,
15    amount_subtotal: Option<i64>,
16    amount_total: Option<i64>,
17}
18
19#[allow(
20    unused_variables,
21    irrefutable_let_patterns,
22    clippy::let_unit_value,
23    clippy::match_single_binding,
24    clippy::single_match
25)]
26const _: () = {
27    use miniserde::de::{Map, Visitor};
28    use miniserde::json::Value;
29    use miniserde::{make_place, Deserialize, Result};
30    use stripe_types::miniserde_helpers::FromValueOpt;
31    use stripe_types::{MapBuilder, ObjectDeser};
32
33    make_place!(Place);
34
35    impl Deserialize for ClimateRemovalsProductsPrice {
36        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
37            Place::new(out)
38        }
39    }
40
41    struct Builder<'a> {
42        out: &'a mut Option<ClimateRemovalsProductsPrice>,
43        builder: ClimateRemovalsProductsPriceBuilder,
44    }
45
46    impl Visitor for Place<ClimateRemovalsProductsPrice> {
47        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
48            Ok(Box::new(Builder {
49                out: &mut self.out,
50                builder: ClimateRemovalsProductsPriceBuilder::deser_default(),
51            }))
52        }
53    }
54
55    impl MapBuilder for ClimateRemovalsProductsPriceBuilder {
56        type Out = ClimateRemovalsProductsPrice;
57        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
58            Ok(match k {
59                "amount_fees" => Deserialize::begin(&mut self.amount_fees),
60                "amount_subtotal" => Deserialize::begin(&mut self.amount_subtotal),
61                "amount_total" => Deserialize::begin(&mut self.amount_total),
62
63                _ => <dyn Visitor>::ignore(),
64            })
65        }
66
67        fn deser_default() -> Self {
68            Self {
69                amount_fees: Deserialize::default(),
70                amount_subtotal: Deserialize::default(),
71                amount_total: Deserialize::default(),
72            }
73        }
74
75        fn take_out(&mut self) -> Option<Self::Out> {
76            let (Some(amount_fees), Some(amount_subtotal), Some(amount_total)) =
77                (self.amount_fees, self.amount_subtotal, self.amount_total)
78            else {
79                return None;
80            };
81            Some(Self::Out { amount_fees, amount_subtotal, amount_total })
82        }
83    }
84
85    impl Map for Builder<'_> {
86        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
87            self.builder.key(k)
88        }
89
90        fn finish(&mut self) -> Result<()> {
91            *self.out = self.builder.take_out();
92            Ok(())
93        }
94    }
95
96    impl ObjectDeser for ClimateRemovalsProductsPrice {
97        type Builder = ClimateRemovalsProductsPriceBuilder;
98    }
99
100    impl FromValueOpt for ClimateRemovalsProductsPrice {
101        fn from_value(v: Value) -> Option<Self> {
102            let Value::Object(obj) = v else {
103                return None;
104            };
105            let mut b = ClimateRemovalsProductsPriceBuilder::deser_default();
106            for (k, v) in obj {
107                match k.as_str() {
108                    "amount_fees" => b.amount_fees = FromValueOpt::from_value(v),
109                    "amount_subtotal" => b.amount_subtotal = FromValueOpt::from_value(v),
110                    "amount_total" => b.amount_total = FromValueOpt::from_value(v),
111
112                    _ => {}
113                }
114            }
115            b.take_out()
116        }
117    }
118};