stripe_shared/
us_bank_account_networks.rs1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct UsBankAccountNetworks {
5 pub preferred: Option<String>,
7 pub supported: Vec<UsBankAccountNetworksSupported>,
9}
10#[doc(hidden)]
11pub struct UsBankAccountNetworksBuilder {
12 preferred: Option<Option<String>>,
13 supported: Option<Vec<UsBankAccountNetworksSupported>>,
14}
15
16#[allow(
17 unused_variables,
18 irrefutable_let_patterns,
19 clippy::let_unit_value,
20 clippy::match_single_binding,
21 clippy::single_match
22)]
23const _: () = {
24 use miniserde::de::{Map, Visitor};
25 use miniserde::json::Value;
26 use miniserde::{Deserialize, Result, make_place};
27 use stripe_types::miniserde_helpers::FromValueOpt;
28 use stripe_types::{MapBuilder, ObjectDeser};
29
30 make_place!(Place);
31
32 impl Deserialize for UsBankAccountNetworks {
33 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
34 Place::new(out)
35 }
36 }
37
38 struct Builder<'a> {
39 out: &'a mut Option<UsBankAccountNetworks>,
40 builder: UsBankAccountNetworksBuilder,
41 }
42
43 impl Visitor for Place<UsBankAccountNetworks> {
44 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
45 Ok(Box::new(Builder {
46 out: &mut self.out,
47 builder: UsBankAccountNetworksBuilder::deser_default(),
48 }))
49 }
50 }
51
52 impl MapBuilder for UsBankAccountNetworksBuilder {
53 type Out = UsBankAccountNetworks;
54 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
55 Ok(match k {
56 "preferred" => Deserialize::begin(&mut self.preferred),
57 "supported" => Deserialize::begin(&mut self.supported),
58 _ => <dyn Visitor>::ignore(),
59 })
60 }
61
62 fn deser_default() -> Self {
63 Self { preferred: Deserialize::default(), supported: Deserialize::default() }
64 }
65
66 fn take_out(&mut self) -> Option<Self::Out> {
67 let (Some(preferred), Some(supported)) = (self.preferred.take(), self.supported.take())
68 else {
69 return None;
70 };
71 Some(Self::Out { preferred, supported })
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 UsBankAccountNetworks {
87 type Builder = UsBankAccountNetworksBuilder;
88 }
89
90 impl FromValueOpt for UsBankAccountNetworks {
91 fn from_value(v: Value) -> Option<Self> {
92 let Value::Object(obj) = v else {
93 return None;
94 };
95 let mut b = UsBankAccountNetworksBuilder::deser_default();
96 for (k, v) in obj {
97 match k.as_str() {
98 "preferred" => b.preferred = FromValueOpt::from_value(v),
99 "supported" => b.supported = FromValueOpt::from_value(v),
100 _ => {}
101 }
102 }
103 b.take_out()
104 }
105 }
106};
107#[derive(Clone, Eq, PartialEq)]
109#[non_exhaustive]
110pub enum UsBankAccountNetworksSupported {
111 Ach,
112 UsDomesticWire,
113 Unknown(String),
115}
116impl UsBankAccountNetworksSupported {
117 pub fn as_str(&self) -> &str {
118 use UsBankAccountNetworksSupported::*;
119 match self {
120 Ach => "ach",
121 UsDomesticWire => "us_domestic_wire",
122 Unknown(v) => v,
123 }
124 }
125}
126
127impl std::str::FromStr for UsBankAccountNetworksSupported {
128 type Err = std::convert::Infallible;
129 fn from_str(s: &str) -> Result<Self, Self::Err> {
130 use UsBankAccountNetworksSupported::*;
131 match s {
132 "ach" => Ok(Ach),
133 "us_domestic_wire" => Ok(UsDomesticWire),
134 v => {
135 tracing::warn!(
136 "Unknown value '{}' for enum '{}'",
137 v,
138 "UsBankAccountNetworksSupported"
139 );
140 Ok(Unknown(v.to_owned()))
141 }
142 }
143 }
144}
145impl std::fmt::Display for UsBankAccountNetworksSupported {
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 UsBankAccountNetworksSupported {
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 UsBankAccountNetworksSupported {
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 UsBankAccountNetworksSupported {
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<UsBankAccountNetworksSupported> {
172 fn string(&mut self, s: &str) -> miniserde::Result<()> {
173 use std::str::FromStr;
174 self.out = Some(UsBankAccountNetworksSupported::from_str(s).expect("infallible"));
175 Ok(())
176 }
177}
178
179stripe_types::impl_from_val_with_from_str!(UsBankAccountNetworksSupported);
180#[cfg(feature = "deserialize")]
181impl<'de> serde::Deserialize<'de> for UsBankAccountNetworksSupported {
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}