stripe_misc/
tax_product_registrations_resource_country_options_simplified.rs

1#[derive(Copy, Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct TaxProductRegistrationsResourceCountryOptionsSimplified {
5    /// Type of registration in `country`.
6    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
7    pub type_: TaxProductRegistrationsResourceCountryOptionsSimplifiedType,
8}
9#[doc(hidden)]
10pub struct TaxProductRegistrationsResourceCountryOptionsSimplifiedBuilder {
11    type_: Option<TaxProductRegistrationsResourceCountryOptionsSimplifiedType>,
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::{Deserialize, Result, make_place};
25    use stripe_types::miniserde_helpers::FromValueOpt;
26    use stripe_types::{MapBuilder, ObjectDeser};
27
28    make_place!(Place);
29
30    impl Deserialize for TaxProductRegistrationsResourceCountryOptionsSimplified {
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<TaxProductRegistrationsResourceCountryOptionsSimplified>,
38        builder: TaxProductRegistrationsResourceCountryOptionsSimplifiedBuilder,
39    }
40
41    impl Visitor for Place<TaxProductRegistrationsResourceCountryOptionsSimplified> {
42        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
43            Ok(Box::new(Builder {
44                out: &mut self.out,
45                builder:
46                    TaxProductRegistrationsResourceCountryOptionsSimplifiedBuilder::deser_default(),
47            }))
48        }
49    }
50
51    impl MapBuilder for TaxProductRegistrationsResourceCountryOptionsSimplifiedBuilder {
52        type Out = TaxProductRegistrationsResourceCountryOptionsSimplified;
53        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
54            Ok(match k {
55                "type" => Deserialize::begin(&mut self.type_),
56                _ => <dyn Visitor>::ignore(),
57            })
58        }
59
60        fn deser_default() -> Self {
61            Self { type_: Deserialize::default() }
62        }
63
64        fn take_out(&mut self) -> Option<Self::Out> {
65            let (Some(type_),) = (self.type_,) else {
66                return None;
67            };
68            Some(Self::Out { type_ })
69        }
70    }
71
72    impl Map for Builder<'_> {
73        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
74            self.builder.key(k)
75        }
76
77        fn finish(&mut self) -> Result<()> {
78            *self.out = self.builder.take_out();
79            Ok(())
80        }
81    }
82
83    impl ObjectDeser for TaxProductRegistrationsResourceCountryOptionsSimplified {
84        type Builder = TaxProductRegistrationsResourceCountryOptionsSimplifiedBuilder;
85    }
86
87    impl FromValueOpt for TaxProductRegistrationsResourceCountryOptionsSimplified {
88        fn from_value(v: Value) -> Option<Self> {
89            let Value::Object(obj) = v else {
90                return None;
91            };
92            let mut b =
93                TaxProductRegistrationsResourceCountryOptionsSimplifiedBuilder::deser_default();
94            for (k, v) in obj {
95                match k.as_str() {
96                    "type" => b.type_ = FromValueOpt::from_value(v),
97                    _ => {}
98                }
99            }
100            b.take_out()
101        }
102    }
103};
104/// Type of registration in `country`.
105#[derive(Copy, Clone, Eq, PartialEq)]
106pub enum TaxProductRegistrationsResourceCountryOptionsSimplifiedType {
107    Simplified,
108}
109impl TaxProductRegistrationsResourceCountryOptionsSimplifiedType {
110    pub fn as_str(self) -> &'static str {
111        use TaxProductRegistrationsResourceCountryOptionsSimplifiedType::*;
112        match self {
113            Simplified => "simplified",
114        }
115    }
116}
117
118impl std::str::FromStr for TaxProductRegistrationsResourceCountryOptionsSimplifiedType {
119    type Err = stripe_types::StripeParseError;
120    fn from_str(s: &str) -> Result<Self, Self::Err> {
121        use TaxProductRegistrationsResourceCountryOptionsSimplifiedType::*;
122        match s {
123            "simplified" => Ok(Simplified),
124            _ => Err(stripe_types::StripeParseError),
125        }
126    }
127}
128impl std::fmt::Display for TaxProductRegistrationsResourceCountryOptionsSimplifiedType {
129    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
130        f.write_str(self.as_str())
131    }
132}
133
134impl std::fmt::Debug for TaxProductRegistrationsResourceCountryOptionsSimplifiedType {
135    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
136        f.write_str(self.as_str())
137    }
138}
139#[cfg(feature = "serialize")]
140impl serde::Serialize for TaxProductRegistrationsResourceCountryOptionsSimplifiedType {
141    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
142    where
143        S: serde::Serializer,
144    {
145        serializer.serialize_str(self.as_str())
146    }
147}
148impl miniserde::Deserialize for TaxProductRegistrationsResourceCountryOptionsSimplifiedType {
149    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
150        crate::Place::new(out)
151    }
152}
153
154impl miniserde::de::Visitor
155    for crate::Place<TaxProductRegistrationsResourceCountryOptionsSimplifiedType>
156{
157    fn string(&mut self, s: &str) -> miniserde::Result<()> {
158        use std::str::FromStr;
159        self.out = Some(
160            TaxProductRegistrationsResourceCountryOptionsSimplifiedType::from_str(s)
161                .map_err(|_| miniserde::Error)?,
162        );
163        Ok(())
164    }
165}
166
167stripe_types::impl_from_val_with_from_str!(
168    TaxProductRegistrationsResourceCountryOptionsSimplifiedType
169);
170#[cfg(feature = "deserialize")]
171impl<'de> serde::Deserialize<'de> for TaxProductRegistrationsResourceCountryOptionsSimplifiedType {
172    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
173        use std::str::FromStr;
174        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
175        Self::from_str(&s).map_err(|_| {
176            serde::de::Error::custom(
177                "Unknown value for TaxProductRegistrationsResourceCountryOptionsSimplifiedType",
178            )
179        })
180    }
181}