stripe_shared/
billing_credit_grants_resource_amount.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct BillingCreditGrantsResourceAmount {
5    /// The monetary amount.
6    pub monetary: Option<stripe_shared::BillingCreditGrantsResourceMonetaryAmount>,
7    /// The type of this amount. We currently only support `monetary` billing credits.
8    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
9    pub type_: BillingCreditGrantsResourceAmountType,
10}
11#[doc(hidden)]
12pub struct BillingCreditGrantsResourceAmountBuilder {
13    monetary: Option<Option<stripe_shared::BillingCreditGrantsResourceMonetaryAmount>>,
14    type_: Option<BillingCreditGrantsResourceAmountType>,
15}
16
17#[allow(
18    unused_variables,
19    irrefutable_let_patterns,
20    clippy::let_unit_value,
21    clippy::match_single_binding,
22    clippy::single_match
23)]
24const _: () = {
25    use miniserde::de::{Map, Visitor};
26    use miniserde::json::Value;
27    use miniserde::{Deserialize, Result, make_place};
28    use stripe_types::miniserde_helpers::FromValueOpt;
29    use stripe_types::{MapBuilder, ObjectDeser};
30
31    make_place!(Place);
32
33    impl Deserialize for BillingCreditGrantsResourceAmount {
34        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
35            Place::new(out)
36        }
37    }
38
39    struct Builder<'a> {
40        out: &'a mut Option<BillingCreditGrantsResourceAmount>,
41        builder: BillingCreditGrantsResourceAmountBuilder,
42    }
43
44    impl Visitor for Place<BillingCreditGrantsResourceAmount> {
45        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
46            Ok(Box::new(Builder {
47                out: &mut self.out,
48                builder: BillingCreditGrantsResourceAmountBuilder::deser_default(),
49            }))
50        }
51    }
52
53    impl MapBuilder for BillingCreditGrantsResourceAmountBuilder {
54        type Out = BillingCreditGrantsResourceAmount;
55        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
56            Ok(match k {
57                "monetary" => Deserialize::begin(&mut self.monetary),
58                "type" => Deserialize::begin(&mut self.type_),
59                _ => <dyn Visitor>::ignore(),
60            })
61        }
62
63        fn deser_default() -> Self {
64            Self { monetary: Deserialize::default(), type_: Deserialize::default() }
65        }
66
67        fn take_out(&mut self) -> Option<Self::Out> {
68            let (Some(monetary), Some(type_)) = (self.monetary.take(), self.type_) else {
69                return None;
70            };
71            Some(Self::Out { monetary, type_ })
72        }
73    }
74
75    impl Map for Builder<'_> {
76        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
77            self.builder.key(k)
78        }
79
80        fn finish(&mut self) -> Result<()> {
81            *self.out = self.builder.take_out();
82            Ok(())
83        }
84    }
85
86    impl ObjectDeser for BillingCreditGrantsResourceAmount {
87        type Builder = BillingCreditGrantsResourceAmountBuilder;
88    }
89
90    impl FromValueOpt for BillingCreditGrantsResourceAmount {
91        fn from_value(v: Value) -> Option<Self> {
92            let Value::Object(obj) = v else {
93                return None;
94            };
95            let mut b = BillingCreditGrantsResourceAmountBuilder::deser_default();
96            for (k, v) in obj {
97                match k.as_str() {
98                    "monetary" => b.monetary = FromValueOpt::from_value(v),
99                    "type" => b.type_ = FromValueOpt::from_value(v),
100                    _ => {}
101                }
102            }
103            b.take_out()
104        }
105    }
106};
107/// The type of this amount. We currently only support `monetary` billing credits.
108#[derive(Copy, Clone, Eq, PartialEq)]
109pub enum BillingCreditGrantsResourceAmountType {
110    Monetary,
111}
112impl BillingCreditGrantsResourceAmountType {
113    pub fn as_str(self) -> &'static str {
114        use BillingCreditGrantsResourceAmountType::*;
115        match self {
116            Monetary => "monetary",
117        }
118    }
119}
120
121impl std::str::FromStr for BillingCreditGrantsResourceAmountType {
122    type Err = stripe_types::StripeParseError;
123    fn from_str(s: &str) -> Result<Self, Self::Err> {
124        use BillingCreditGrantsResourceAmountType::*;
125        match s {
126            "monetary" => Ok(Monetary),
127            _ => Err(stripe_types::StripeParseError),
128        }
129    }
130}
131impl std::fmt::Display for BillingCreditGrantsResourceAmountType {
132    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
133        f.write_str(self.as_str())
134    }
135}
136
137impl std::fmt::Debug for BillingCreditGrantsResourceAmountType {
138    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
139        f.write_str(self.as_str())
140    }
141}
142#[cfg(feature = "serialize")]
143impl serde::Serialize for BillingCreditGrantsResourceAmountType {
144    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
145    where
146        S: serde::Serializer,
147    {
148        serializer.serialize_str(self.as_str())
149    }
150}
151impl miniserde::Deserialize for BillingCreditGrantsResourceAmountType {
152    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
153        crate::Place::new(out)
154    }
155}
156
157impl miniserde::de::Visitor for crate::Place<BillingCreditGrantsResourceAmountType> {
158    fn string(&mut self, s: &str) -> miniserde::Result<()> {
159        use std::str::FromStr;
160        self.out =
161            Some(BillingCreditGrantsResourceAmountType::from_str(s).map_err(|_| miniserde::Error)?);
162        Ok(())
163    }
164}
165
166stripe_types::impl_from_val_with_from_str!(BillingCreditGrantsResourceAmountType);
167#[cfg(feature = "deserialize")]
168impl<'de> serde::Deserialize<'de> for BillingCreditGrantsResourceAmountType {
169    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
170        use std::str::FromStr;
171        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
172        Self::from_str(&s).map_err(|_| {
173            serde::de::Error::custom("Unknown value for BillingCreditGrantsResourceAmountType")
174        })
175    }
176}