stripe_shared/
connect_account_reference.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct ConnectAccountReference {
5    /// The connected account being referenced when `type` is `account`.
6    pub account: Option<stripe_types::Expandable<stripe_shared::Account>>,
7    /// Type of the account referenced.
8    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
9    pub type_: ConnectAccountReferenceType,
10}
11#[doc(hidden)]
12pub struct ConnectAccountReferenceBuilder {
13    account: Option<Option<stripe_types::Expandable<stripe_shared::Account>>>,
14    type_: Option<ConnectAccountReferenceType>,
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 ConnectAccountReference {
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<ConnectAccountReference>,
41        builder: ConnectAccountReferenceBuilder,
42    }
43
44    impl Visitor for Place<ConnectAccountReference> {
45        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
46            Ok(Box::new(Builder {
47                out: &mut self.out,
48                builder: ConnectAccountReferenceBuilder::deser_default(),
49            }))
50        }
51    }
52
53    impl MapBuilder for ConnectAccountReferenceBuilder {
54        type Out = ConnectAccountReference;
55        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
56            Ok(match k {
57                "account" => Deserialize::begin(&mut self.account),
58                "type" => Deserialize::begin(&mut self.type_),
59                _ => <dyn Visitor>::ignore(),
60            })
61        }
62
63        fn deser_default() -> Self {
64            Self { account: Deserialize::default(), type_: Deserialize::default() }
65        }
66
67        fn take_out(&mut self) -> Option<Self::Out> {
68            let (Some(account), Some(type_)) = (self.account.take(), self.type_.take()) else {
69                return None;
70            };
71            Some(Self::Out { account, 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 ConnectAccountReference {
87        type Builder = ConnectAccountReferenceBuilder;
88    }
89
90    impl FromValueOpt for ConnectAccountReference {
91        fn from_value(v: Value) -> Option<Self> {
92            let Value::Object(obj) = v else {
93                return None;
94            };
95            let mut b = ConnectAccountReferenceBuilder::deser_default();
96            for (k, v) in obj {
97                match k.as_str() {
98                    "account" => b.account = FromValueOpt::from_value(v),
99                    "type" => b.type_ = FromValueOpt::from_value(v),
100                    _ => {}
101                }
102            }
103            b.take_out()
104        }
105    }
106};
107/// Type of the account referenced.
108#[derive(Clone, Eq, PartialEq)]
109#[non_exhaustive]
110pub enum ConnectAccountReferenceType {
111    Account,
112    Self_,
113    /// An unrecognized value from Stripe. Should not be used as a request parameter.
114    Unknown(String),
115}
116impl ConnectAccountReferenceType {
117    pub fn as_str(&self) -> &str {
118        use ConnectAccountReferenceType::*;
119        match self {
120            Account => "account",
121            Self_ => "self",
122            Unknown(v) => v,
123        }
124    }
125}
126
127impl std::str::FromStr for ConnectAccountReferenceType {
128    type Err = std::convert::Infallible;
129    fn from_str(s: &str) -> Result<Self, Self::Err> {
130        use ConnectAccountReferenceType::*;
131        match s {
132            "account" => Ok(Account),
133            "self" => Ok(Self_),
134            v => {
135                tracing::warn!(
136                    "Unknown value '{}' for enum '{}'",
137                    v,
138                    "ConnectAccountReferenceType"
139                );
140                Ok(Unknown(v.to_owned()))
141            }
142        }
143    }
144}
145impl std::fmt::Display for ConnectAccountReferenceType {
146    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
147        f.write_str(self.as_str())
148    }
149}
150
151impl std::fmt::Debug for ConnectAccountReferenceType {
152    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
153        f.write_str(self.as_str())
154    }
155}
156#[cfg(feature = "serialize")]
157impl serde::Serialize for ConnectAccountReferenceType {
158    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
159    where
160        S: serde::Serializer,
161    {
162        serializer.serialize_str(self.as_str())
163    }
164}
165impl miniserde::Deserialize for ConnectAccountReferenceType {
166    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
167        crate::Place::new(out)
168    }
169}
170
171impl miniserde::de::Visitor for crate::Place<ConnectAccountReferenceType> {
172    fn string(&mut self, s: &str) -> miniserde::Result<()> {
173        use std::str::FromStr;
174        self.out = Some(ConnectAccountReferenceType::from_str(s).expect("infallible"));
175        Ok(())
176    }
177}
178
179stripe_types::impl_from_val_with_from_str!(ConnectAccountReferenceType);
180#[cfg(feature = "deserialize")]
181impl<'de> serde::Deserialize<'de> for ConnectAccountReferenceType {
182    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
183        use std::str::FromStr;
184        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
185        Ok(Self::from_str(&s).expect("infallible"))
186    }
187}