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::{Deserialize, Result, make_place};
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                _ => <dyn Visitor>::ignore(),
63            })
64        }
65
66        fn deser_default() -> Self {
67            Self {
68                amount_fees: Deserialize::default(),
69                amount_subtotal: Deserialize::default(),
70                amount_total: Deserialize::default(),
71            }
72        }
73
74        fn take_out(&mut self) -> Option<Self::Out> {
75            let (Some(amount_fees), Some(amount_subtotal), Some(amount_total)) =
76                (self.amount_fees, self.amount_subtotal, self.amount_total)
77            else {
78                return None;
79            };
80            Some(Self::Out { amount_fees, amount_subtotal, amount_total })
81        }
82    }
83
84    impl Map for Builder<'_> {
85        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
86            self.builder.key(k)
87        }
88
89        fn finish(&mut self) -> Result<()> {
90            *self.out = self.builder.take_out();
91            Ok(())
92        }
93    }
94
95    impl ObjectDeser for ClimateRemovalsProductsPrice {
96        type Builder = ClimateRemovalsProductsPriceBuilder;
97    }
98
99    impl FromValueOpt for ClimateRemovalsProductsPrice {
100        fn from_value(v: Value) -> Option<Self> {
101            let Value::Object(obj) = v else {
102                return None;
103            };
104            let mut b = ClimateRemovalsProductsPriceBuilder::deser_default();
105            for (k, v) in obj {
106                match k.as_str() {
107                    "amount_fees" => b.amount_fees = FromValueOpt::from_value(v),
108                    "amount_subtotal" => b.amount_subtotal = FromValueOpt::from_value(v),
109                    "amount_total" => b.amount_total = FromValueOpt::from_value(v),
110                    _ => {}
111                }
112            }
113            b.take_out()
114        }
115    }
116};