Skip to main content

stripe_shared/
legal_entity_representative_declaration.rs

1#[derive(Clone, Eq, PartialEq)]
2#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct LegalEntityRepresentativeDeclaration {
6    /// The Unix timestamp marking when the representative declaration attestation was made.
7    pub date: Option<stripe_types::Timestamp>,
8    /// The IP address from which the representative declaration attestation was made.
9    pub ip: Option<String>,
10    /// The user-agent string from the browser where the representative declaration attestation was made.
11    pub user_agent: Option<String>,
12}
13#[cfg(feature = "redact-generated-debug")]
14impl std::fmt::Debug for LegalEntityRepresentativeDeclaration {
15    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
16        f.debug_struct("LegalEntityRepresentativeDeclaration").finish_non_exhaustive()
17    }
18}
19#[doc(hidden)]
20pub struct LegalEntityRepresentativeDeclarationBuilder {
21    date: Option<Option<stripe_types::Timestamp>>,
22    ip: Option<Option<String>>,
23    user_agent: Option<Option<String>>,
24}
25
26#[allow(
27    unused_variables,
28    irrefutable_let_patterns,
29    clippy::let_unit_value,
30    clippy::match_single_binding,
31    clippy::single_match
32)]
33const _: () = {
34    use miniserde::de::{Map, Visitor};
35    use miniserde::json::Value;
36    use miniserde::{Deserialize, Result, make_place};
37    use stripe_types::miniserde_helpers::FromValueOpt;
38    use stripe_types::{MapBuilder, ObjectDeser};
39
40    make_place!(Place);
41
42    impl Deserialize for LegalEntityRepresentativeDeclaration {
43        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
44            Place::new(out)
45        }
46    }
47
48    struct Builder<'a> {
49        out: &'a mut Option<LegalEntityRepresentativeDeclaration>,
50        builder: LegalEntityRepresentativeDeclarationBuilder,
51    }
52
53    impl Visitor for Place<LegalEntityRepresentativeDeclaration> {
54        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
55            Ok(Box::new(Builder {
56                out: &mut self.out,
57                builder: LegalEntityRepresentativeDeclarationBuilder::deser_default(),
58            }))
59        }
60    }
61
62    impl MapBuilder for LegalEntityRepresentativeDeclarationBuilder {
63        type Out = LegalEntityRepresentativeDeclaration;
64        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
65            Ok(match k {
66                "date" => Deserialize::begin(&mut self.date),
67                "ip" => Deserialize::begin(&mut self.ip),
68                "user_agent" => Deserialize::begin(&mut self.user_agent),
69                _ => <dyn Visitor>::ignore(),
70            })
71        }
72
73        fn deser_default() -> Self {
74            Self { date: Some(None), ip: Some(None), user_agent: Some(None) }
75        }
76
77        fn take_out(&mut self) -> Option<Self::Out> {
78            let (Some(date), Some(ip), Some(user_agent)) =
79                (self.date, self.ip.take(), self.user_agent.take())
80            else {
81                return None;
82            };
83            Some(Self::Out { date, ip, user_agent })
84        }
85    }
86
87    impl Map for Builder<'_> {
88        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
89            self.builder.key(k)
90        }
91
92        fn finish(&mut self) -> Result<()> {
93            *self.out = self.builder.take_out();
94            Ok(())
95        }
96    }
97
98    impl ObjectDeser for LegalEntityRepresentativeDeclaration {
99        type Builder = LegalEntityRepresentativeDeclarationBuilder;
100    }
101
102    impl FromValueOpt for LegalEntityRepresentativeDeclaration {
103        fn from_value(v: Value) -> Option<Self> {
104            let Value::Object(obj) = v else {
105                return None;
106            };
107            let mut b = LegalEntityRepresentativeDeclarationBuilder::deser_default();
108            for (k, v) in obj {
109                match k.as_str() {
110                    "date" => b.date = FromValueOpt::from_value(v),
111                    "ip" => b.ip = FromValueOpt::from_value(v),
112                    "user_agent" => b.user_agent = FromValueOpt::from_value(v),
113                    _ => {}
114                }
115            }
116            b.take_out()
117        }
118    }
119};