stripe_shared/
source_type_eps.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct SourceTypeEps {
5    pub reference: Option<String>,
6    pub statement_descriptor: Option<String>,
7}
8#[doc(hidden)]
9pub struct SourceTypeEpsBuilder {
10    reference: Option<Option<String>>,
11    statement_descriptor: Option<Option<String>>,
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::{make_place, Deserialize, Result};
25    use stripe_types::miniserde_helpers::FromValueOpt;
26    use stripe_types::{MapBuilder, ObjectDeser};
27
28    make_place!(Place);
29
30    impl Deserialize for SourceTypeEps {
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<SourceTypeEps>,
38        builder: SourceTypeEpsBuilder,
39    }
40
41    impl Visitor for Place<SourceTypeEps> {
42        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
43            Ok(Box::new(Builder {
44                out: &mut self.out,
45                builder: SourceTypeEpsBuilder::deser_default(),
46            }))
47        }
48    }
49
50    impl MapBuilder for SourceTypeEpsBuilder {
51        type Out = SourceTypeEps;
52        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
53            Ok(match k {
54                "reference" => Deserialize::begin(&mut self.reference),
55                "statement_descriptor" => Deserialize::begin(&mut self.statement_descriptor),
56
57                _ => <dyn Visitor>::ignore(),
58            })
59        }
60
61        fn deser_default() -> Self {
62            Self { reference: Deserialize::default(), statement_descriptor: Deserialize::default() }
63        }
64
65        fn take_out(&mut self) -> Option<Self::Out> {
66            let (Some(reference), Some(statement_descriptor)) =
67                (self.reference.take(), self.statement_descriptor.take())
68            else {
69                return None;
70            };
71            Some(Self::Out { reference, statement_descriptor })
72        }
73    }
74
75    impl<'a> Map for Builder<'a> {
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 SourceTypeEps {
87        type Builder = SourceTypeEpsBuilder;
88    }
89
90    impl FromValueOpt for SourceTypeEps {
91        fn from_value(v: Value) -> Option<Self> {
92            let Value::Object(obj) = v else {
93                return None;
94            };
95            let mut b = SourceTypeEpsBuilder::deser_default();
96            for (k, v) in obj {
97                match k.as_str() {
98                    "reference" => b.reference = FromValueOpt::from_value(v),
99                    "statement_descriptor" => b.statement_descriptor = FromValueOpt::from_value(v),
100
101                    _ => {}
102                }
103            }
104            b.take_out()
105        }
106    }
107};