stripe_misc/
climate_removals_location.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct ClimateRemovalsLocation {
5    /// The city where the supplier is located.
6    pub city: Option<String>,
7    /// Two-letter ISO code representing the country where the supplier is located.
8    pub country: String,
9    /// The geographic latitude where the supplier is located.
10    pub latitude: Option<f64>,
11    /// The geographic longitude where the supplier is located.
12    pub longitude: Option<f64>,
13    /// The state/county/province/region where the supplier is located.
14    pub region: Option<String>,
15}
16#[doc(hidden)]
17pub struct ClimateRemovalsLocationBuilder {
18    city: Option<Option<String>>,
19    country: Option<String>,
20    latitude: Option<Option<f64>>,
21    longitude: Option<Option<f64>>,
22    region: Option<Option<String>>,
23}
24
25#[allow(
26    unused_variables,
27    irrefutable_let_patterns,
28    clippy::let_unit_value,
29    clippy::match_single_binding,
30    clippy::single_match
31)]
32const _: () = {
33    use miniserde::de::{Map, Visitor};
34    use miniserde::json::Value;
35    use miniserde::{Deserialize, Result, make_place};
36    use stripe_types::miniserde_helpers::FromValueOpt;
37    use stripe_types::{MapBuilder, ObjectDeser};
38
39    make_place!(Place);
40
41    impl Deserialize for ClimateRemovalsLocation {
42        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
43            Place::new(out)
44        }
45    }
46
47    struct Builder<'a> {
48        out: &'a mut Option<ClimateRemovalsLocation>,
49        builder: ClimateRemovalsLocationBuilder,
50    }
51
52    impl Visitor for Place<ClimateRemovalsLocation> {
53        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
54            Ok(Box::new(Builder {
55                out: &mut self.out,
56                builder: ClimateRemovalsLocationBuilder::deser_default(),
57            }))
58        }
59    }
60
61    impl MapBuilder for ClimateRemovalsLocationBuilder {
62        type Out = ClimateRemovalsLocation;
63        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
64            Ok(match k {
65                "city" => Deserialize::begin(&mut self.city),
66                "country" => Deserialize::begin(&mut self.country),
67                "latitude" => Deserialize::begin(&mut self.latitude),
68                "longitude" => Deserialize::begin(&mut self.longitude),
69                "region" => Deserialize::begin(&mut self.region),
70                _ => <dyn Visitor>::ignore(),
71            })
72        }
73
74        fn deser_default() -> Self {
75            Self {
76                city: Deserialize::default(),
77                country: Deserialize::default(),
78                latitude: Deserialize::default(),
79                longitude: Deserialize::default(),
80                region: Deserialize::default(),
81            }
82        }
83
84        fn take_out(&mut self) -> Option<Self::Out> {
85            let (Some(city), Some(country), Some(latitude), Some(longitude), Some(region)) = (
86                self.city.take(),
87                self.country.take(),
88                self.latitude,
89                self.longitude,
90                self.region.take(),
91            ) else {
92                return None;
93            };
94            Some(Self::Out { city, country, latitude, longitude, region })
95        }
96    }
97
98    impl Map for Builder<'_> {
99        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
100            self.builder.key(k)
101        }
102
103        fn finish(&mut self) -> Result<()> {
104            *self.out = self.builder.take_out();
105            Ok(())
106        }
107    }
108
109    impl ObjectDeser for ClimateRemovalsLocation {
110        type Builder = ClimateRemovalsLocationBuilder;
111    }
112
113    impl FromValueOpt for ClimateRemovalsLocation {
114        fn from_value(v: Value) -> Option<Self> {
115            let Value::Object(obj) = v else {
116                return None;
117            };
118            let mut b = ClimateRemovalsLocationBuilder::deser_default();
119            for (k, v) in obj {
120                match k.as_str() {
121                    "city" => b.city = FromValueOpt::from_value(v),
122                    "country" => b.country = FromValueOpt::from_value(v),
123                    "latitude" => b.latitude = FromValueOpt::from_value(v),
124                    "longitude" => b.longitude = FromValueOpt::from_value(v),
125                    "region" => b.region = FromValueOpt::from_value(v),
126                    _ => {}
127                }
128            }
129            b.take_out()
130        }
131    }
132};