stripe_misc/
tax_product_resource_jurisdiction.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct TaxProductResourceJurisdiction {
5    /// Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
6    pub country: String,
7    /// A human-readable name for the jurisdiction imposing the tax.
8    pub display_name: String,
9    /// Indicates the level of the jurisdiction imposing the tax.
10    pub level: TaxProductResourceJurisdictionLevel,
11    /// [ISO 3166-2 subdivision code](https://en.wikipedia.org/wiki/ISO_3166-2), without country prefix.
12    /// For example, "NY" for New York, United States.
13    pub state: Option<String>,
14}
15#[doc(hidden)]
16pub struct TaxProductResourceJurisdictionBuilder {
17    country: Option<String>,
18    display_name: Option<String>,
19    level: Option<TaxProductResourceJurisdictionLevel>,
20    state: Option<Option<String>>,
21}
22
23#[allow(
24    unused_variables,
25    irrefutable_let_patterns,
26    clippy::let_unit_value,
27    clippy::match_single_binding,
28    clippy::single_match
29)]
30const _: () = {
31    use miniserde::de::{Map, Visitor};
32    use miniserde::json::Value;
33    use miniserde::{Deserialize, Result, make_place};
34    use stripe_types::miniserde_helpers::FromValueOpt;
35    use stripe_types::{MapBuilder, ObjectDeser};
36
37    make_place!(Place);
38
39    impl Deserialize for TaxProductResourceJurisdiction {
40        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
41            Place::new(out)
42        }
43    }
44
45    struct Builder<'a> {
46        out: &'a mut Option<TaxProductResourceJurisdiction>,
47        builder: TaxProductResourceJurisdictionBuilder,
48    }
49
50    impl Visitor for Place<TaxProductResourceJurisdiction> {
51        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
52            Ok(Box::new(Builder {
53                out: &mut self.out,
54                builder: TaxProductResourceJurisdictionBuilder::deser_default(),
55            }))
56        }
57    }
58
59    impl MapBuilder for TaxProductResourceJurisdictionBuilder {
60        type Out = TaxProductResourceJurisdiction;
61        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
62            Ok(match k {
63                "country" => Deserialize::begin(&mut self.country),
64                "display_name" => Deserialize::begin(&mut self.display_name),
65                "level" => Deserialize::begin(&mut self.level),
66                "state" => Deserialize::begin(&mut self.state),
67                _ => <dyn Visitor>::ignore(),
68            })
69        }
70
71        fn deser_default() -> Self {
72            Self {
73                country: Deserialize::default(),
74                display_name: Deserialize::default(),
75                level: Deserialize::default(),
76                state: Deserialize::default(),
77            }
78        }
79
80        fn take_out(&mut self) -> Option<Self::Out> {
81            let (Some(country), Some(display_name), Some(level), Some(state)) =
82                (self.country.take(), self.display_name.take(), self.level, self.state.take())
83            else {
84                return None;
85            };
86            Some(Self::Out { country, display_name, level, state })
87        }
88    }
89
90    impl Map for Builder<'_> {
91        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
92            self.builder.key(k)
93        }
94
95        fn finish(&mut self) -> Result<()> {
96            *self.out = self.builder.take_out();
97            Ok(())
98        }
99    }
100
101    impl ObjectDeser for TaxProductResourceJurisdiction {
102        type Builder = TaxProductResourceJurisdictionBuilder;
103    }
104
105    impl FromValueOpt for TaxProductResourceJurisdiction {
106        fn from_value(v: Value) -> Option<Self> {
107            let Value::Object(obj) = v else {
108                return None;
109            };
110            let mut b = TaxProductResourceJurisdictionBuilder::deser_default();
111            for (k, v) in obj {
112                match k.as_str() {
113                    "country" => b.country = FromValueOpt::from_value(v),
114                    "display_name" => b.display_name = FromValueOpt::from_value(v),
115                    "level" => b.level = FromValueOpt::from_value(v),
116                    "state" => b.state = FromValueOpt::from_value(v),
117                    _ => {}
118                }
119            }
120            b.take_out()
121        }
122    }
123};
124/// Indicates the level of the jurisdiction imposing the tax.
125#[derive(Copy, Clone, Eq, PartialEq)]
126pub enum TaxProductResourceJurisdictionLevel {
127    City,
128    Country,
129    County,
130    District,
131    State,
132}
133impl TaxProductResourceJurisdictionLevel {
134    pub fn as_str(self) -> &'static str {
135        use TaxProductResourceJurisdictionLevel::*;
136        match self {
137            City => "city",
138            Country => "country",
139            County => "county",
140            District => "district",
141            State => "state",
142        }
143    }
144}
145
146impl std::str::FromStr for TaxProductResourceJurisdictionLevel {
147    type Err = stripe_types::StripeParseError;
148    fn from_str(s: &str) -> Result<Self, Self::Err> {
149        use TaxProductResourceJurisdictionLevel::*;
150        match s {
151            "city" => Ok(City),
152            "country" => Ok(Country),
153            "county" => Ok(County),
154            "district" => Ok(District),
155            "state" => Ok(State),
156            _ => Err(stripe_types::StripeParseError),
157        }
158    }
159}
160impl std::fmt::Display for TaxProductResourceJurisdictionLevel {
161    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
162        f.write_str(self.as_str())
163    }
164}
165
166impl std::fmt::Debug for TaxProductResourceJurisdictionLevel {
167    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
168        f.write_str(self.as_str())
169    }
170}
171#[cfg(feature = "serialize")]
172impl serde::Serialize for TaxProductResourceJurisdictionLevel {
173    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
174    where
175        S: serde::Serializer,
176    {
177        serializer.serialize_str(self.as_str())
178    }
179}
180impl miniserde::Deserialize for TaxProductResourceJurisdictionLevel {
181    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
182        crate::Place::new(out)
183    }
184}
185
186impl miniserde::de::Visitor for crate::Place<TaxProductResourceJurisdictionLevel> {
187    fn string(&mut self, s: &str) -> miniserde::Result<()> {
188        use std::str::FromStr;
189        self.out =
190            Some(TaxProductResourceJurisdictionLevel::from_str(s).map_err(|_| miniserde::Error)?);
191        Ok(())
192    }
193}
194
195stripe_types::impl_from_val_with_from_str!(TaxProductResourceJurisdictionLevel);
196#[cfg(feature = "deserialize")]
197impl<'de> serde::Deserialize<'de> for TaxProductResourceJurisdictionLevel {
198    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
199        use std::str::FromStr;
200        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
201        Self::from_str(&s).map_err(|_| {
202            serde::de::Error::custom("Unknown value for TaxProductResourceJurisdictionLevel")
203        })
204    }
205}