stripe_shared/
legal_entity_japan_address.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct LegalEntityJapanAddress {
5    /// City/Ward.
6    pub city: Option<String>,
7    /// Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
8    pub country: Option<String>,
9    /// Block/Building number.
10    pub line1: Option<String>,
11    /// Building details.
12    pub line2: Option<String>,
13    /// ZIP or postal code.
14    pub postal_code: Option<String>,
15    /// Prefecture.
16    pub state: Option<String>,
17    /// Town/cho-me.
18    pub town: Option<String>,
19}
20#[doc(hidden)]
21pub struct LegalEntityJapanAddressBuilder {
22    city: Option<Option<String>>,
23    country: Option<Option<String>>,
24    line1: Option<Option<String>>,
25    line2: Option<Option<String>>,
26    postal_code: Option<Option<String>>,
27    state: Option<Option<String>>,
28    town: Option<Option<String>>,
29}
30
31#[allow(
32    unused_variables,
33    irrefutable_let_patterns,
34    clippy::let_unit_value,
35    clippy::match_single_binding,
36    clippy::single_match
37)]
38const _: () = {
39    use miniserde::de::{Map, Visitor};
40    use miniserde::json::Value;
41    use miniserde::{Deserialize, Result, make_place};
42    use stripe_types::miniserde_helpers::FromValueOpt;
43    use stripe_types::{MapBuilder, ObjectDeser};
44
45    make_place!(Place);
46
47    impl Deserialize for LegalEntityJapanAddress {
48        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
49            Place::new(out)
50        }
51    }
52
53    struct Builder<'a> {
54        out: &'a mut Option<LegalEntityJapanAddress>,
55        builder: LegalEntityJapanAddressBuilder,
56    }
57
58    impl Visitor for Place<LegalEntityJapanAddress> {
59        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
60            Ok(Box::new(Builder {
61                out: &mut self.out,
62                builder: LegalEntityJapanAddressBuilder::deser_default(),
63            }))
64        }
65    }
66
67    impl MapBuilder for LegalEntityJapanAddressBuilder {
68        type Out = LegalEntityJapanAddress;
69        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
70            Ok(match k {
71                "city" => Deserialize::begin(&mut self.city),
72                "country" => Deserialize::begin(&mut self.country),
73                "line1" => Deserialize::begin(&mut self.line1),
74                "line2" => Deserialize::begin(&mut self.line2),
75                "postal_code" => Deserialize::begin(&mut self.postal_code),
76                "state" => Deserialize::begin(&mut self.state),
77                "town" => Deserialize::begin(&mut self.town),
78
79                _ => <dyn Visitor>::ignore(),
80            })
81        }
82
83        fn deser_default() -> Self {
84            Self {
85                city: Deserialize::default(),
86                country: Deserialize::default(),
87                line1: Deserialize::default(),
88                line2: Deserialize::default(),
89                postal_code: Deserialize::default(),
90                state: Deserialize::default(),
91                town: Deserialize::default(),
92            }
93        }
94
95        fn take_out(&mut self) -> Option<Self::Out> {
96            let (
97                Some(city),
98                Some(country),
99                Some(line1),
100                Some(line2),
101                Some(postal_code),
102                Some(state),
103                Some(town),
104            ) = (
105                self.city.take(),
106                self.country.take(),
107                self.line1.take(),
108                self.line2.take(),
109                self.postal_code.take(),
110                self.state.take(),
111                self.town.take(),
112            )
113            else {
114                return None;
115            };
116            Some(Self::Out { city, country, line1, line2, postal_code, state, town })
117        }
118    }
119
120    impl Map for Builder<'_> {
121        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
122            self.builder.key(k)
123        }
124
125        fn finish(&mut self) -> Result<()> {
126            *self.out = self.builder.take_out();
127            Ok(())
128        }
129    }
130
131    impl ObjectDeser for LegalEntityJapanAddress {
132        type Builder = LegalEntityJapanAddressBuilder;
133    }
134
135    impl FromValueOpt for LegalEntityJapanAddress {
136        fn from_value(v: Value) -> Option<Self> {
137            let Value::Object(obj) = v else {
138                return None;
139            };
140            let mut b = LegalEntityJapanAddressBuilder::deser_default();
141            for (k, v) in obj {
142                match k.as_str() {
143                    "city" => b.city = FromValueOpt::from_value(v),
144                    "country" => b.country = FromValueOpt::from_value(v),
145                    "line1" => b.line1 = FromValueOpt::from_value(v),
146                    "line2" => b.line2 = FromValueOpt::from_value(v),
147                    "postal_code" => b.postal_code = FromValueOpt::from_value(v),
148                    "state" => b.state = FromValueOpt::from_value(v),
149                    "town" => b.town = FromValueOpt::from_value(v),
150
151                    _ => {}
152                }
153            }
154            b.take_out()
155        }
156    }
157};