stripe_shared/
account_monthly_estimated_revenue.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct AccountMonthlyEstimatedRevenue {
5    /// A non-negative integer representing how much to charge in the [smallest currency unit](/currencies#zero-decimal).
6    pub amount: i64,
7    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
8    /// Must be a [supported currency](https://stripe.com/docs/currencies).
9    pub currency: stripe_types::Currency,
10}
11#[doc(hidden)]
12pub struct AccountMonthlyEstimatedRevenueBuilder {
13    amount: Option<i64>,
14    currency: Option<stripe_types::Currency>,
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 AccountMonthlyEstimatedRevenue {
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<AccountMonthlyEstimatedRevenue>,
41        builder: AccountMonthlyEstimatedRevenueBuilder,
42    }
43
44    impl Visitor for Place<AccountMonthlyEstimatedRevenue> {
45        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
46            Ok(Box::new(Builder {
47                out: &mut self.out,
48                builder: AccountMonthlyEstimatedRevenueBuilder::deser_default(),
49            }))
50        }
51    }
52
53    impl MapBuilder for AccountMonthlyEstimatedRevenueBuilder {
54        type Out = AccountMonthlyEstimatedRevenue;
55        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
56            Ok(match k {
57                "amount" => Deserialize::begin(&mut self.amount),
58                "currency" => Deserialize::begin(&mut self.currency),
59                _ => <dyn Visitor>::ignore(),
60            })
61        }
62
63        fn deser_default() -> Self {
64            Self { amount: Deserialize::default(), currency: Deserialize::default() }
65        }
66
67        fn take_out(&mut self) -> Option<Self::Out> {
68            let (Some(amount), Some(currency)) = (self.amount, self.currency.take()) else {
69                return None;
70            };
71            Some(Self::Out { amount, currency })
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 AccountMonthlyEstimatedRevenue {
87        type Builder = AccountMonthlyEstimatedRevenueBuilder;
88    }
89
90    impl FromValueOpt for AccountMonthlyEstimatedRevenue {
91        fn from_value(v: Value) -> Option<Self> {
92            let Value::Object(obj) = v else {
93                return None;
94            };
95            let mut b = AccountMonthlyEstimatedRevenueBuilder::deser_default();
96            for (k, v) in obj {
97                match k.as_str() {
98                    "amount" => b.amount = FromValueOpt::from_value(v),
99                    "currency" => b.currency = FromValueOpt::from_value(v),
100                    _ => {}
101                }
102            }
103            b.take_out()
104        }
105    }
106};