stripe_misc/
climate_removals_location.rs1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct ClimateRemovalsLocation {
5 pub city: Option<String>,
7 pub country: String,
9 pub latitude: Option<f64>,
11 pub longitude: Option<f64>,
13 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
71 _ => <dyn Visitor>::ignore(),
72 })
73 }
74
75 fn deser_default() -> Self {
76 Self {
77 city: Deserialize::default(),
78 country: Deserialize::default(),
79 latitude: Deserialize::default(),
80 longitude: Deserialize::default(),
81 region: Deserialize::default(),
82 }
83 }
84
85 fn take_out(&mut self) -> Option<Self::Out> {
86 let (Some(city), Some(country), Some(latitude), Some(longitude), Some(region)) = (
87 self.city.take(),
88 self.country.take(),
89 self.latitude,
90 self.longitude,
91 self.region.take(),
92 ) else {
93 return None;
94 };
95 Some(Self::Out { city, country, latitude, longitude, region })
96 }
97 }
98
99 impl Map for Builder<'_> {
100 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
101 self.builder.key(k)
102 }
103
104 fn finish(&mut self) -> Result<()> {
105 *self.out = self.builder.take_out();
106 Ok(())
107 }
108 }
109
110 impl ObjectDeser for ClimateRemovalsLocation {
111 type Builder = ClimateRemovalsLocationBuilder;
112 }
113
114 impl FromValueOpt for ClimateRemovalsLocation {
115 fn from_value(v: Value) -> Option<Self> {
116 let Value::Object(obj) = v else {
117 return None;
118 };
119 let mut b = ClimateRemovalsLocationBuilder::deser_default();
120 for (k, v) in obj {
121 match k.as_str() {
122 "city" => b.city = FromValueOpt::from_value(v),
123 "country" => b.country = FromValueOpt::from_value(v),
124 "latitude" => b.latitude = FromValueOpt::from_value(v),
125 "longitude" => b.longitude = FromValueOpt::from_value(v),
126 "region" => b.region = FromValueOpt::from_value(v),
127
128 _ => {}
129 }
130 }
131 b.take_out()
132 }
133 }
134};