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