stripe_shared/
issuing_transaction_fuel_data.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct IssuingTransactionFuelData {
5    /// [Conexxus Payment System Product Code](https://www.conexxus.org/conexxus-payment-system-product-codes) identifying the primary fuel product purchased.
6    pub industry_product_code: Option<String>,
7    /// The quantity of `unit`s of fuel that was dispensed, represented as a decimal string with at most 12 decimal places.
8    pub quantity_decimal: Option<String>,
9    /// The type of fuel that was purchased.
10    /// One of `diesel`, `unleaded_plus`, `unleaded_regular`, `unleaded_super`, or `other`.
11    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
12    pub type_: String,
13    /// The units for `quantity_decimal`.
14    /// One of `charging_minute`, `imperial_gallon`, `kilogram`, `kilowatt_hour`, `liter`, `pound`, `us_gallon`, or `other`.
15    pub unit: String,
16    /// The cost in cents per each unit of fuel, represented as a decimal string with at most 12 decimal places.
17    pub unit_cost_decimal: String,
18}
19#[doc(hidden)]
20pub struct IssuingTransactionFuelDataBuilder {
21    industry_product_code: Option<Option<String>>,
22    quantity_decimal: Option<Option<String>>,
23    type_: Option<String>,
24    unit: Option<String>,
25    unit_cost_decimal: Option<String>,
26}
27
28#[allow(
29    unused_variables,
30    irrefutable_let_patterns,
31    clippy::let_unit_value,
32    clippy::match_single_binding,
33    clippy::single_match
34)]
35const _: () = {
36    use miniserde::de::{Map, Visitor};
37    use miniserde::json::Value;
38    use miniserde::{Deserialize, Result, make_place};
39    use stripe_types::miniserde_helpers::FromValueOpt;
40    use stripe_types::{MapBuilder, ObjectDeser};
41
42    make_place!(Place);
43
44    impl Deserialize for IssuingTransactionFuelData {
45        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
46            Place::new(out)
47        }
48    }
49
50    struct Builder<'a> {
51        out: &'a mut Option<IssuingTransactionFuelData>,
52        builder: IssuingTransactionFuelDataBuilder,
53    }
54
55    impl Visitor for Place<IssuingTransactionFuelData> {
56        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
57            Ok(Box::new(Builder {
58                out: &mut self.out,
59                builder: IssuingTransactionFuelDataBuilder::deser_default(),
60            }))
61        }
62    }
63
64    impl MapBuilder for IssuingTransactionFuelDataBuilder {
65        type Out = IssuingTransactionFuelData;
66        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
67            Ok(match k {
68                "industry_product_code" => Deserialize::begin(&mut self.industry_product_code),
69                "quantity_decimal" => Deserialize::begin(&mut self.quantity_decimal),
70                "type" => Deserialize::begin(&mut self.type_),
71                "unit" => Deserialize::begin(&mut self.unit),
72                "unit_cost_decimal" => Deserialize::begin(&mut self.unit_cost_decimal),
73                _ => <dyn Visitor>::ignore(),
74            })
75        }
76
77        fn deser_default() -> Self {
78            Self {
79                industry_product_code: Deserialize::default(),
80                quantity_decimal: Deserialize::default(),
81                type_: Deserialize::default(),
82                unit: Deserialize::default(),
83                unit_cost_decimal: Deserialize::default(),
84            }
85        }
86
87        fn take_out(&mut self) -> Option<Self::Out> {
88            let (
89                Some(industry_product_code),
90                Some(quantity_decimal),
91                Some(type_),
92                Some(unit),
93                Some(unit_cost_decimal),
94            ) = (
95                self.industry_product_code.take(),
96                self.quantity_decimal.take(),
97                self.type_.take(),
98                self.unit.take(),
99                self.unit_cost_decimal.take(),
100            )
101            else {
102                return None;
103            };
104            Some(Self::Out {
105                industry_product_code,
106                quantity_decimal,
107                type_,
108                unit,
109                unit_cost_decimal,
110            })
111        }
112    }
113
114    impl Map for Builder<'_> {
115        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
116            self.builder.key(k)
117        }
118
119        fn finish(&mut self) -> Result<()> {
120            *self.out = self.builder.take_out();
121            Ok(())
122        }
123    }
124
125    impl ObjectDeser for IssuingTransactionFuelData {
126        type Builder = IssuingTransactionFuelDataBuilder;
127    }
128
129    impl FromValueOpt for IssuingTransactionFuelData {
130        fn from_value(v: Value) -> Option<Self> {
131            let Value::Object(obj) = v else {
132                return None;
133            };
134            let mut b = IssuingTransactionFuelDataBuilder::deser_default();
135            for (k, v) in obj {
136                match k.as_str() {
137                    "industry_product_code" => {
138                        b.industry_product_code = FromValueOpt::from_value(v)
139                    }
140                    "quantity_decimal" => b.quantity_decimal = FromValueOpt::from_value(v),
141                    "type" => b.type_ = FromValueOpt::from_value(v),
142                    "unit" => b.unit = FromValueOpt::from_value(v),
143                    "unit_cost_decimal" => b.unit_cost_decimal = FromValueOpt::from_value(v),
144                    _ => {}
145                }
146            }
147            b.take_out()
148        }
149    }
150};