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(),
83                self.display_name.take(),
84                self.level.take(),
85                self.state.take(),
86            ) else {
87                return None;
88            };
89            Some(Self::Out { country, display_name, level, state })
90        }
91    }
92
93    impl Map for Builder<'_> {
94        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
95            self.builder.key(k)
96        }
97
98        fn finish(&mut self) -> Result<()> {
99            *self.out = self.builder.take_out();
100            Ok(())
101        }
102    }
103
104    impl ObjectDeser for TaxProductResourceJurisdiction {
105        type Builder = TaxProductResourceJurisdictionBuilder;
106    }
107
108    impl FromValueOpt for TaxProductResourceJurisdiction {
109        fn from_value(v: Value) -> Option<Self> {
110            let Value::Object(obj) = v else {
111                return None;
112            };
113            let mut b = TaxProductResourceJurisdictionBuilder::deser_default();
114            for (k, v) in obj {
115                match k.as_str() {
116                    "country" => b.country = FromValueOpt::from_value(v),
117                    "display_name" => b.display_name = FromValueOpt::from_value(v),
118                    "level" => b.level = FromValueOpt::from_value(v),
119                    "state" => b.state = FromValueOpt::from_value(v),
120                    _ => {}
121                }
122            }
123            b.take_out()
124        }
125    }
126};
127/// Indicates the level of the jurisdiction imposing the tax.
128#[derive(Clone, Eq, PartialEq)]
129#[non_exhaustive]
130pub enum TaxProductResourceJurisdictionLevel {
131    City,
132    Country,
133    County,
134    District,
135    State,
136    /// An unrecognized value from Stripe. Should not be used as a request parameter.
137    Unknown(String),
138}
139impl TaxProductResourceJurisdictionLevel {
140    pub fn as_str(&self) -> &str {
141        use TaxProductResourceJurisdictionLevel::*;
142        match self {
143            City => "city",
144            Country => "country",
145            County => "county",
146            District => "district",
147            State => "state",
148            Unknown(v) => v,
149        }
150    }
151}
152
153impl std::str::FromStr for TaxProductResourceJurisdictionLevel {
154    type Err = std::convert::Infallible;
155    fn from_str(s: &str) -> Result<Self, Self::Err> {
156        use TaxProductResourceJurisdictionLevel::*;
157        match s {
158            "city" => Ok(City),
159            "country" => Ok(Country),
160            "county" => Ok(County),
161            "district" => Ok(District),
162            "state" => Ok(State),
163            v => {
164                tracing::warn!(
165                    "Unknown value '{}' for enum '{}'",
166                    v,
167                    "TaxProductResourceJurisdictionLevel"
168                );
169                Ok(Unknown(v.to_owned()))
170            }
171        }
172    }
173}
174impl std::fmt::Display for TaxProductResourceJurisdictionLevel {
175    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
176        f.write_str(self.as_str())
177    }
178}
179
180impl std::fmt::Debug for TaxProductResourceJurisdictionLevel {
181    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
182        f.write_str(self.as_str())
183    }
184}
185#[cfg(feature = "serialize")]
186impl serde::Serialize for TaxProductResourceJurisdictionLevel {
187    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
188    where
189        S: serde::Serializer,
190    {
191        serializer.serialize_str(self.as_str())
192    }
193}
194impl miniserde::Deserialize for TaxProductResourceJurisdictionLevel {
195    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
196        crate::Place::new(out)
197    }
198}
199
200impl miniserde::de::Visitor for crate::Place<TaxProductResourceJurisdictionLevel> {
201    fn string(&mut self, s: &str) -> miniserde::Result<()> {
202        use std::str::FromStr;
203        self.out = Some(TaxProductResourceJurisdictionLevel::from_str(s).expect("infallible"));
204        Ok(())
205    }
206}
207
208stripe_types::impl_from_val_with_from_str!(TaxProductResourceJurisdictionLevel);
209#[cfg(feature = "deserialize")]
210impl<'de> serde::Deserialize<'de> for TaxProductResourceJurisdictionLevel {
211    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
212        use std::str::FromStr;
213        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
214        Ok(Self::from_str(&s).expect("infallible"))
215    }
216}