stripe_misc/climate_supplier/
types.rs1#[derive(Clone, Debug)]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct ClimateSupplier {
5 pub id: stripe_misc::ClimateSupplierId,
7 pub info_url: String,
9 pub livemode: bool,
11 pub locations: Vec<stripe_misc::ClimateRemovalsLocation>,
13 pub name: String,
15 pub removal_pathway: ClimateSupplierRemovalPathway,
17}
18#[doc(hidden)]
19pub struct ClimateSupplierBuilder {
20 id: Option<stripe_misc::ClimateSupplierId>,
21 info_url: Option<String>,
22 livemode: Option<bool>,
23 locations: Option<Vec<stripe_misc::ClimateRemovalsLocation>>,
24 name: Option<String>,
25 removal_pathway: Option<ClimateSupplierRemovalPathway>,
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 ClimateSupplier {
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<ClimateSupplier>,
52 builder: ClimateSupplierBuilder,
53 }
54
55 impl Visitor for Place<ClimateSupplier> {
56 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
57 Ok(Box::new(Builder {
58 out: &mut self.out,
59 builder: ClimateSupplierBuilder::deser_default(),
60 }))
61 }
62 }
63
64 impl MapBuilder for ClimateSupplierBuilder {
65 type Out = ClimateSupplier;
66 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
67 Ok(match k {
68 "id" => Deserialize::begin(&mut self.id),
69 "info_url" => Deserialize::begin(&mut self.info_url),
70 "livemode" => Deserialize::begin(&mut self.livemode),
71 "locations" => Deserialize::begin(&mut self.locations),
72 "name" => Deserialize::begin(&mut self.name),
73 "removal_pathway" => Deserialize::begin(&mut self.removal_pathway),
74 _ => <dyn Visitor>::ignore(),
75 })
76 }
77
78 fn deser_default() -> Self {
79 Self {
80 id: Deserialize::default(),
81 info_url: Deserialize::default(),
82 livemode: Deserialize::default(),
83 locations: Deserialize::default(),
84 name: Deserialize::default(),
85 removal_pathway: Deserialize::default(),
86 }
87 }
88
89 fn take_out(&mut self) -> Option<Self::Out> {
90 let (
91 Some(id),
92 Some(info_url),
93 Some(livemode),
94 Some(locations),
95 Some(name),
96 Some(removal_pathway),
97 ) = (
98 self.id.take(),
99 self.info_url.take(),
100 self.livemode,
101 self.locations.take(),
102 self.name.take(),
103 self.removal_pathway.take(),
104 )
105 else {
106 return None;
107 };
108 Some(Self::Out { id, info_url, livemode, locations, name, removal_pathway })
109 }
110 }
111
112 impl Map for Builder<'_> {
113 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
114 self.builder.key(k)
115 }
116
117 fn finish(&mut self) -> Result<()> {
118 *self.out = self.builder.take_out();
119 Ok(())
120 }
121 }
122
123 impl ObjectDeser for ClimateSupplier {
124 type Builder = ClimateSupplierBuilder;
125 }
126
127 impl FromValueOpt for ClimateSupplier {
128 fn from_value(v: Value) -> Option<Self> {
129 let Value::Object(obj) = v else {
130 return None;
131 };
132 let mut b = ClimateSupplierBuilder::deser_default();
133 for (k, v) in obj {
134 match k.as_str() {
135 "id" => b.id = FromValueOpt::from_value(v),
136 "info_url" => b.info_url = FromValueOpt::from_value(v),
137 "livemode" => b.livemode = FromValueOpt::from_value(v),
138 "locations" => b.locations = FromValueOpt::from_value(v),
139 "name" => b.name = FromValueOpt::from_value(v),
140 "removal_pathway" => b.removal_pathway = FromValueOpt::from_value(v),
141 _ => {}
142 }
143 }
144 b.take_out()
145 }
146 }
147};
148#[cfg(feature = "serialize")]
149impl serde::Serialize for ClimateSupplier {
150 fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
151 use serde::ser::SerializeStruct;
152 let mut s = s.serialize_struct("ClimateSupplier", 7)?;
153 s.serialize_field("id", &self.id)?;
154 s.serialize_field("info_url", &self.info_url)?;
155 s.serialize_field("livemode", &self.livemode)?;
156 s.serialize_field("locations", &self.locations)?;
157 s.serialize_field("name", &self.name)?;
158 s.serialize_field("removal_pathway", &self.removal_pathway)?;
159
160 s.serialize_field("object", "climate.supplier")?;
161 s.end()
162 }
163}
164#[derive(Clone, Eq, PartialEq)]
166#[non_exhaustive]
167pub enum ClimateSupplierRemovalPathway {
168 BiomassCarbonRemovalAndStorage,
169 DirectAirCapture,
170 EnhancedWeathering,
171 Unknown(String),
173}
174impl ClimateSupplierRemovalPathway {
175 pub fn as_str(&self) -> &str {
176 use ClimateSupplierRemovalPathway::*;
177 match self {
178 BiomassCarbonRemovalAndStorage => "biomass_carbon_removal_and_storage",
179 DirectAirCapture => "direct_air_capture",
180 EnhancedWeathering => "enhanced_weathering",
181 Unknown(v) => v,
182 }
183 }
184}
185
186impl std::str::FromStr for ClimateSupplierRemovalPathway {
187 type Err = std::convert::Infallible;
188 fn from_str(s: &str) -> Result<Self, Self::Err> {
189 use ClimateSupplierRemovalPathway::*;
190 match s {
191 "biomass_carbon_removal_and_storage" => Ok(BiomassCarbonRemovalAndStorage),
192 "direct_air_capture" => Ok(DirectAirCapture),
193 "enhanced_weathering" => Ok(EnhancedWeathering),
194 v => {
195 tracing::warn!(
196 "Unknown value '{}' for enum '{}'",
197 v,
198 "ClimateSupplierRemovalPathway"
199 );
200 Ok(Unknown(v.to_owned()))
201 }
202 }
203 }
204}
205impl std::fmt::Display for ClimateSupplierRemovalPathway {
206 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
207 f.write_str(self.as_str())
208 }
209}
210
211impl std::fmt::Debug for ClimateSupplierRemovalPathway {
212 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
213 f.write_str(self.as_str())
214 }
215}
216#[cfg(feature = "serialize")]
217impl serde::Serialize for ClimateSupplierRemovalPathway {
218 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
219 where
220 S: serde::Serializer,
221 {
222 serializer.serialize_str(self.as_str())
223 }
224}
225impl miniserde::Deserialize for ClimateSupplierRemovalPathway {
226 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
227 crate::Place::new(out)
228 }
229}
230
231impl miniserde::de::Visitor for crate::Place<ClimateSupplierRemovalPathway> {
232 fn string(&mut self, s: &str) -> miniserde::Result<()> {
233 use std::str::FromStr;
234 self.out = Some(ClimateSupplierRemovalPathway::from_str(s).expect("infallible"));
235 Ok(())
236 }
237}
238
239stripe_types::impl_from_val_with_from_str!(ClimateSupplierRemovalPathway);
240#[cfg(feature = "deserialize")]
241impl<'de> serde::Deserialize<'de> for ClimateSupplierRemovalPathway {
242 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
243 use std::str::FromStr;
244 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
245 Ok(Self::from_str(&s).expect("infallible"))
246 }
247}
248impl stripe_types::Object for ClimateSupplier {
249 type Id = stripe_misc::ClimateSupplierId;
250 fn id(&self) -> &Self::Id {
251 &self.id
252 }
253
254 fn into_id(self) -> Self::Id {
255 self.id
256 }
257}
258stripe_types::def_id!(ClimateSupplierId);