stripe_shared/
payment_method_options_us_bank_account_mandate_options.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentMethodOptionsUsBankAccountMandateOptions {
5    /// Mandate collection method
6    pub collection_method: Option<PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod>,
7}
8#[doc(hidden)]
9pub struct PaymentMethodOptionsUsBankAccountMandateOptionsBuilder {
10    collection_method:
11        Option<Option<PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod>>,
12}
13
14#[allow(
15    unused_variables,
16    irrefutable_let_patterns,
17    clippy::let_unit_value,
18    clippy::match_single_binding,
19    clippy::single_match
20)]
21const _: () = {
22    use miniserde::de::{Map, Visitor};
23    use miniserde::json::Value;
24    use miniserde::{Deserialize, Result, make_place};
25    use stripe_types::miniserde_helpers::FromValueOpt;
26    use stripe_types::{MapBuilder, ObjectDeser};
27
28    make_place!(Place);
29
30    impl Deserialize for PaymentMethodOptionsUsBankAccountMandateOptions {
31        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
32            Place::new(out)
33        }
34    }
35
36    struct Builder<'a> {
37        out: &'a mut Option<PaymentMethodOptionsUsBankAccountMandateOptions>,
38        builder: PaymentMethodOptionsUsBankAccountMandateOptionsBuilder,
39    }
40
41    impl Visitor for Place<PaymentMethodOptionsUsBankAccountMandateOptions> {
42        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
43            Ok(Box::new(Builder {
44                out: &mut self.out,
45                builder: PaymentMethodOptionsUsBankAccountMandateOptionsBuilder::deser_default(),
46            }))
47        }
48    }
49
50    impl MapBuilder for PaymentMethodOptionsUsBankAccountMandateOptionsBuilder {
51        type Out = PaymentMethodOptionsUsBankAccountMandateOptions;
52        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
53            Ok(match k {
54                "collection_method" => Deserialize::begin(&mut self.collection_method),
55                _ => <dyn Visitor>::ignore(),
56            })
57        }
58
59        fn deser_default() -> Self {
60            Self { collection_method: Deserialize::default() }
61        }
62
63        fn take_out(&mut self) -> Option<Self::Out> {
64            let (Some(collection_method),) = (self.collection_method.take(),) else {
65                return None;
66            };
67            Some(Self::Out { collection_method })
68        }
69    }
70
71    impl Map for Builder<'_> {
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 PaymentMethodOptionsUsBankAccountMandateOptions {
83        type Builder = PaymentMethodOptionsUsBankAccountMandateOptionsBuilder;
84    }
85
86    impl FromValueOpt for PaymentMethodOptionsUsBankAccountMandateOptions {
87        fn from_value(v: Value) -> Option<Self> {
88            let Value::Object(obj) = v else {
89                return None;
90            };
91            let mut b = PaymentMethodOptionsUsBankAccountMandateOptionsBuilder::deser_default();
92            for (k, v) in obj {
93                match k.as_str() {
94                    "collection_method" => b.collection_method = FromValueOpt::from_value(v),
95                    _ => {}
96                }
97            }
98            b.take_out()
99        }
100    }
101};
102/// Mandate collection method
103#[derive(Clone, Eq, PartialEq)]
104#[non_exhaustive]
105pub enum PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod {
106    Paper,
107    /// An unrecognized value from Stripe. Should not be used as a request parameter.
108    Unknown(String),
109}
110impl PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod {
111    pub fn as_str(&self) -> &str {
112        use PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod::*;
113        match self {
114            Paper => "paper",
115            Unknown(v) => v,
116        }
117    }
118}
119
120impl std::str::FromStr for PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod {
121    type Err = std::convert::Infallible;
122    fn from_str(s: &str) -> Result<Self, Self::Err> {
123        use PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod::*;
124        match s {
125            "paper" => Ok(Paper),
126            v => {
127                tracing::warn!(
128                    "Unknown value '{}' for enum '{}'",
129                    v,
130                    "PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod"
131                );
132                Ok(Unknown(v.to_owned()))
133            }
134        }
135    }
136}
137impl std::fmt::Display for PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod {
138    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
139        f.write_str(self.as_str())
140    }
141}
142
143impl std::fmt::Debug for PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod {
144    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
145        f.write_str(self.as_str())
146    }
147}
148#[cfg(feature = "serialize")]
149impl serde::Serialize for PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod {
150    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
151    where
152        S: serde::Serializer,
153    {
154        serializer.serialize_str(self.as_str())
155    }
156}
157impl miniserde::Deserialize for PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod {
158    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
159        crate::Place::new(out)
160    }
161}
162
163impl miniserde::de::Visitor
164    for crate::Place<PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod>
165{
166    fn string(&mut self, s: &str) -> miniserde::Result<()> {
167        use std::str::FromStr;
168        self.out = Some(
169            PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod::from_str(s)
170                .expect("infallible"),
171        );
172        Ok(())
173    }
174}
175
176stripe_types::impl_from_val_with_from_str!(
177    PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod
178);
179#[cfg(feature = "deserialize")]
180impl<'de> serde::Deserialize<'de>
181    for PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod
182{
183    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
184        use std::str::FromStr;
185        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
186        Ok(Self::from_str(&s).expect("infallible"))
187    }
188}