stripe_shared/
account_unification_account_controller_losses.rs

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