stripe_core/
balance_net_available.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct BalanceNetAvailable {
5    /// Net balance amount, subtracting fees from platform-set pricing.
6    pub amount: i64,
7    /// ID of the external account for this net balance (not expandable).
8    pub destination: String,
9    pub source_types: Option<stripe_core::BalanceAmountBySourceType>,
10}
11#[doc(hidden)]
12pub struct BalanceNetAvailableBuilder {
13    amount: Option<i64>,
14    destination: Option<String>,
15    source_types: Option<Option<stripe_core::BalanceAmountBySourceType>>,
16}
17
18#[allow(
19    unused_variables,
20    irrefutable_let_patterns,
21    clippy::let_unit_value,
22    clippy::match_single_binding,
23    clippy::single_match
24)]
25const _: () = {
26    use miniserde::de::{Map, Visitor};
27    use miniserde::json::Value;
28    use miniserde::{Deserialize, Result, make_place};
29    use stripe_types::miniserde_helpers::FromValueOpt;
30    use stripe_types::{MapBuilder, ObjectDeser};
31
32    make_place!(Place);
33
34    impl Deserialize for BalanceNetAvailable {
35        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
36            Place::new(out)
37        }
38    }
39
40    struct Builder<'a> {
41        out: &'a mut Option<BalanceNetAvailable>,
42        builder: BalanceNetAvailableBuilder,
43    }
44
45    impl Visitor for Place<BalanceNetAvailable> {
46        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
47            Ok(Box::new(Builder {
48                out: &mut self.out,
49                builder: BalanceNetAvailableBuilder::deser_default(),
50            }))
51        }
52    }
53
54    impl MapBuilder for BalanceNetAvailableBuilder {
55        type Out = BalanceNetAvailable;
56        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
57            Ok(match k {
58                "amount" => Deserialize::begin(&mut self.amount),
59                "destination" => Deserialize::begin(&mut self.destination),
60                "source_types" => Deserialize::begin(&mut self.source_types),
61                _ => <dyn Visitor>::ignore(),
62            })
63        }
64
65        fn deser_default() -> Self {
66            Self {
67                amount: Deserialize::default(),
68                destination: Deserialize::default(),
69                source_types: Deserialize::default(),
70            }
71        }
72
73        fn take_out(&mut self) -> Option<Self::Out> {
74            let (Some(amount), Some(destination), Some(source_types)) =
75                (self.amount, self.destination.take(), self.source_types)
76            else {
77                return None;
78            };
79            Some(Self::Out { amount, destination, source_types })
80        }
81    }
82
83    impl Map for Builder<'_> {
84        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
85            self.builder.key(k)
86        }
87
88        fn finish(&mut self) -> Result<()> {
89            *self.out = self.builder.take_out();
90            Ok(())
91        }
92    }
93
94    impl ObjectDeser for BalanceNetAvailable {
95        type Builder = BalanceNetAvailableBuilder;
96    }
97
98    impl FromValueOpt for BalanceNetAvailable {
99        fn from_value(v: Value) -> Option<Self> {
100            let Value::Object(obj) = v else {
101                return None;
102            };
103            let mut b = BalanceNetAvailableBuilder::deser_default();
104            for (k, v) in obj {
105                match k.as_str() {
106                    "amount" => b.amount = FromValueOpt::from_value(v),
107                    "destination" => b.destination = FromValueOpt::from_value(v),
108                    "source_types" => b.source_types = FromValueOpt::from_value(v),
109                    _ => {}
110                }
111            }
112            b.take_out()
113        }
114    }
115};