stripe_misc/climate_supplier/
types.rs

1/// A supplier of carbon removal.
2#[derive(Clone, Debug)]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct ClimateSupplier {
5    /// Unique identifier for the object.
6    pub id: stripe_misc::ClimateSupplierId,
7    /// Link to a webpage to learn more about the supplier.
8    pub info_url: String,
9    /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
10    pub livemode: bool,
11    /// The locations in which this supplier operates.
12    pub locations: Vec<stripe_misc::ClimateRemovalsLocation>,
13    /// Name of this carbon removal supplier.
14    pub name: String,
15    /// The scientific pathway used for carbon removal.
16    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,
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/// The scientific pathway used for carbon removal.
165#[derive(Copy, Clone, Eq, PartialEq)]
166pub enum ClimateSupplierRemovalPathway {
167    BiomassCarbonRemovalAndStorage,
168    DirectAirCapture,
169    EnhancedWeathering,
170}
171impl ClimateSupplierRemovalPathway {
172    pub fn as_str(self) -> &'static str {
173        use ClimateSupplierRemovalPathway::*;
174        match self {
175            BiomassCarbonRemovalAndStorage => "biomass_carbon_removal_and_storage",
176            DirectAirCapture => "direct_air_capture",
177            EnhancedWeathering => "enhanced_weathering",
178        }
179    }
180}
181
182impl std::str::FromStr for ClimateSupplierRemovalPathway {
183    type Err = stripe_types::StripeParseError;
184    fn from_str(s: &str) -> Result<Self, Self::Err> {
185        use ClimateSupplierRemovalPathway::*;
186        match s {
187            "biomass_carbon_removal_and_storage" => Ok(BiomassCarbonRemovalAndStorage),
188            "direct_air_capture" => Ok(DirectAirCapture),
189            "enhanced_weathering" => Ok(EnhancedWeathering),
190            _ => Err(stripe_types::StripeParseError),
191        }
192    }
193}
194impl std::fmt::Display for ClimateSupplierRemovalPathway {
195    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
196        f.write_str(self.as_str())
197    }
198}
199
200impl std::fmt::Debug for ClimateSupplierRemovalPathway {
201    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
202        f.write_str(self.as_str())
203    }
204}
205#[cfg(feature = "serialize")]
206impl serde::Serialize for ClimateSupplierRemovalPathway {
207    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
208    where
209        S: serde::Serializer,
210    {
211        serializer.serialize_str(self.as_str())
212    }
213}
214impl miniserde::Deserialize for ClimateSupplierRemovalPathway {
215    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
216        crate::Place::new(out)
217    }
218}
219
220impl miniserde::de::Visitor for crate::Place<ClimateSupplierRemovalPathway> {
221    fn string(&mut self, s: &str) -> miniserde::Result<()> {
222        use std::str::FromStr;
223        self.out = Some(ClimateSupplierRemovalPathway::from_str(s).map_err(|_| miniserde::Error)?);
224        Ok(())
225    }
226}
227
228stripe_types::impl_from_val_with_from_str!(ClimateSupplierRemovalPathway);
229#[cfg(feature = "deserialize")]
230impl<'de> serde::Deserialize<'de> for ClimateSupplierRemovalPathway {
231    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
232        use std::str::FromStr;
233        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
234        Self::from_str(&s).map_err(|_| {
235            serde::de::Error::custom("Unknown value for ClimateSupplierRemovalPathway")
236        })
237    }
238}
239impl stripe_types::Object for ClimateSupplier {
240    type Id = stripe_misc::ClimateSupplierId;
241    fn id(&self) -> &Self::Id {
242        &self.id
243    }
244
245    fn into_id(self) -> Self::Id {
246        self.id
247    }
248}
249stripe_types::def_id!(ClimateSupplierId);