stripe_misc/
tax_product_registrations_resource_country_options_default.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct TaxProductRegistrationsResourceCountryOptionsDefault {
5    /// Type of registration in `country`.
6    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
7    pub type_: TaxProductRegistrationsResourceCountryOptionsDefaultType,
8}
9#[doc(hidden)]
10pub struct TaxProductRegistrationsResourceCountryOptionsDefaultBuilder {
11    type_: Option<TaxProductRegistrationsResourceCountryOptionsDefaultType>,
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 TaxProductRegistrationsResourceCountryOptionsDefault {
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<TaxProductRegistrationsResourceCountryOptionsDefault>,
38        builder: TaxProductRegistrationsResourceCountryOptionsDefaultBuilder,
39    }
40
41    impl Visitor for Place<TaxProductRegistrationsResourceCountryOptionsDefault> {
42        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
43            Ok(Box::new(Builder {
44                out: &mut self.out,
45                builder: TaxProductRegistrationsResourceCountryOptionsDefaultBuilder::deser_default(
46                ),
47            }))
48        }
49    }
50
51    impl MapBuilder for TaxProductRegistrationsResourceCountryOptionsDefaultBuilder {
52        type Out = TaxProductRegistrationsResourceCountryOptionsDefault;
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_.take(),) 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 TaxProductRegistrationsResourceCountryOptionsDefault {
84        type Builder = TaxProductRegistrationsResourceCountryOptionsDefaultBuilder;
85    }
86
87    impl FromValueOpt for TaxProductRegistrationsResourceCountryOptionsDefault {
88        fn from_value(v: Value) -> Option<Self> {
89            let Value::Object(obj) = v else {
90                return None;
91            };
92            let mut b =
93                TaxProductRegistrationsResourceCountryOptionsDefaultBuilder::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(Clone, Eq, PartialEq)]
106#[non_exhaustive]
107pub enum TaxProductRegistrationsResourceCountryOptionsDefaultType {
108    Standard,
109    /// An unrecognized value from Stripe. Should not be used as a request parameter.
110    Unknown(String),
111}
112impl TaxProductRegistrationsResourceCountryOptionsDefaultType {
113    pub fn as_str(&self) -> &str {
114        use TaxProductRegistrationsResourceCountryOptionsDefaultType::*;
115        match self {
116            Standard => "standard",
117            Unknown(v) => v,
118        }
119    }
120}
121
122impl std::str::FromStr for TaxProductRegistrationsResourceCountryOptionsDefaultType {
123    type Err = std::convert::Infallible;
124    fn from_str(s: &str) -> Result<Self, Self::Err> {
125        use TaxProductRegistrationsResourceCountryOptionsDefaultType::*;
126        match s {
127            "standard" => Ok(Standard),
128            v => {
129                tracing::warn!(
130                    "Unknown value '{}' for enum '{}'",
131                    v,
132                    "TaxProductRegistrationsResourceCountryOptionsDefaultType"
133                );
134                Ok(Unknown(v.to_owned()))
135            }
136        }
137    }
138}
139impl std::fmt::Display for TaxProductRegistrationsResourceCountryOptionsDefaultType {
140    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
141        f.write_str(self.as_str())
142    }
143}
144
145impl std::fmt::Debug for TaxProductRegistrationsResourceCountryOptionsDefaultType {
146    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
147        f.write_str(self.as_str())
148    }
149}
150#[cfg(feature = "serialize")]
151impl serde::Serialize for TaxProductRegistrationsResourceCountryOptionsDefaultType {
152    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
153    where
154        S: serde::Serializer,
155    {
156        serializer.serialize_str(self.as_str())
157    }
158}
159impl miniserde::Deserialize for TaxProductRegistrationsResourceCountryOptionsDefaultType {
160    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
161        crate::Place::new(out)
162    }
163}
164
165impl miniserde::de::Visitor
166    for crate::Place<TaxProductRegistrationsResourceCountryOptionsDefaultType>
167{
168    fn string(&mut self, s: &str) -> miniserde::Result<()> {
169        use std::str::FromStr;
170        self.out = Some(
171            TaxProductRegistrationsResourceCountryOptionsDefaultType::from_str(s)
172                .expect("infallible"),
173        );
174        Ok(())
175    }
176}
177
178stripe_types::impl_from_val_with_from_str!(
179    TaxProductRegistrationsResourceCountryOptionsDefaultType
180);
181#[cfg(feature = "deserialize")]
182impl<'de> serde::Deserialize<'de> for TaxProductRegistrationsResourceCountryOptionsDefaultType {
183    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
184        use std::str::FromStr;
185        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
186        Ok(Self::from_str(&s).expect("infallible"))
187    }
188}