1#[derive(Clone, Eq, PartialEq)]
2#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct IssuingNetworkTokenDevice {
6 pub device_fingerprint: Option<String>,
8 pub ip_address: Option<String>,
10 pub location: Option<String>,
13 pub name: Option<String>,
15 pub phone_number: Option<String>,
17 #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
19 pub type_: Option<IssuingNetworkTokenDeviceType>,
20}
21#[cfg(feature = "redact-generated-debug")]
22impl std::fmt::Debug for IssuingNetworkTokenDevice {
23 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
24 f.debug_struct("IssuingNetworkTokenDevice").finish_non_exhaustive()
25 }
26}
27#[doc(hidden)]
28pub struct IssuingNetworkTokenDeviceBuilder {
29 device_fingerprint: Option<Option<String>>,
30 ip_address: Option<Option<String>>,
31 location: Option<Option<String>>,
32 name: Option<Option<String>>,
33 phone_number: Option<Option<String>>,
34 type_: Option<Option<IssuingNetworkTokenDeviceType>>,
35}
36
37#[allow(
38 unused_variables,
39 irrefutable_let_patterns,
40 clippy::let_unit_value,
41 clippy::match_single_binding,
42 clippy::single_match
43)]
44const _: () = {
45 use miniserde::de::{Map, Visitor};
46 use miniserde::json::Value;
47 use miniserde::{Deserialize, Result, make_place};
48 use stripe_types::miniserde_helpers::FromValueOpt;
49 use stripe_types::{MapBuilder, ObjectDeser};
50
51 make_place!(Place);
52
53 impl Deserialize for IssuingNetworkTokenDevice {
54 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
55 Place::new(out)
56 }
57 }
58
59 struct Builder<'a> {
60 out: &'a mut Option<IssuingNetworkTokenDevice>,
61 builder: IssuingNetworkTokenDeviceBuilder,
62 }
63
64 impl Visitor for Place<IssuingNetworkTokenDevice> {
65 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
66 Ok(Box::new(Builder {
67 out: &mut self.out,
68 builder: IssuingNetworkTokenDeviceBuilder::deser_default(),
69 }))
70 }
71 }
72
73 impl MapBuilder for IssuingNetworkTokenDeviceBuilder {
74 type Out = IssuingNetworkTokenDevice;
75 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
76 Ok(match k {
77 "device_fingerprint" => Deserialize::begin(&mut self.device_fingerprint),
78 "ip_address" => Deserialize::begin(&mut self.ip_address),
79 "location" => Deserialize::begin(&mut self.location),
80 "name" => Deserialize::begin(&mut self.name),
81 "phone_number" => Deserialize::begin(&mut self.phone_number),
82 "type" => Deserialize::begin(&mut self.type_),
83 _ => <dyn Visitor>::ignore(),
84 })
85 }
86
87 fn deser_default() -> Self {
88 Self {
89 device_fingerprint: Some(None),
90 ip_address: Some(None),
91 location: Some(None),
92 name: Some(None),
93 phone_number: Some(None),
94 type_: Some(None),
95 }
96 }
97
98 fn take_out(&mut self) -> Option<Self::Out> {
99 let (
100 Some(device_fingerprint),
101 Some(ip_address),
102 Some(location),
103 Some(name),
104 Some(phone_number),
105 Some(type_),
106 ) = (
107 self.device_fingerprint.take(),
108 self.ip_address.take(),
109 self.location.take(),
110 self.name.take(),
111 self.phone_number.take(),
112 self.type_.take(),
113 )
114 else {
115 return None;
116 };
117 Some(Self::Out { device_fingerprint, ip_address, location, name, phone_number, type_ })
118 }
119 }
120
121 impl Map for Builder<'_> {
122 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
123 self.builder.key(k)
124 }
125
126 fn finish(&mut self) -> Result<()> {
127 *self.out = self.builder.take_out();
128 Ok(())
129 }
130 }
131
132 impl ObjectDeser for IssuingNetworkTokenDevice {
133 type Builder = IssuingNetworkTokenDeviceBuilder;
134 }
135
136 impl FromValueOpt for IssuingNetworkTokenDevice {
137 fn from_value(v: Value) -> Option<Self> {
138 let Value::Object(obj) = v else {
139 return None;
140 };
141 let mut b = IssuingNetworkTokenDeviceBuilder::deser_default();
142 for (k, v) in obj {
143 match k.as_str() {
144 "device_fingerprint" => b.device_fingerprint = FromValueOpt::from_value(v),
145 "ip_address" => b.ip_address = FromValueOpt::from_value(v),
146 "location" => b.location = FromValueOpt::from_value(v),
147 "name" => b.name = FromValueOpt::from_value(v),
148 "phone_number" => b.phone_number = FromValueOpt::from_value(v),
149 "type" => b.type_ = FromValueOpt::from_value(v),
150 _ => {}
151 }
152 }
153 b.take_out()
154 }
155 }
156};
157#[derive(Clone, Eq, PartialEq)]
159#[non_exhaustive]
160pub enum IssuingNetworkTokenDeviceType {
161 Other,
162 Phone,
163 Watch,
164 Unknown(String),
166}
167impl IssuingNetworkTokenDeviceType {
168 pub fn as_str(&self) -> &str {
169 use IssuingNetworkTokenDeviceType::*;
170 match self {
171 Other => "other",
172 Phone => "phone",
173 Watch => "watch",
174 Unknown(v) => v,
175 }
176 }
177}
178
179impl std::str::FromStr for IssuingNetworkTokenDeviceType {
180 type Err = std::convert::Infallible;
181 fn from_str(s: &str) -> Result<Self, Self::Err> {
182 use IssuingNetworkTokenDeviceType::*;
183 match s {
184 "other" => Ok(Other),
185 "phone" => Ok(Phone),
186 "watch" => Ok(Watch),
187 v => {
188 tracing::warn!(
189 "Unknown value '{}' for enum '{}'",
190 v,
191 "IssuingNetworkTokenDeviceType"
192 );
193 Ok(Unknown(v.to_owned()))
194 }
195 }
196 }
197}
198impl std::fmt::Display for IssuingNetworkTokenDeviceType {
199 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
200 f.write_str(self.as_str())
201 }
202}
203
204#[cfg(not(feature = "redact-generated-debug"))]
205impl std::fmt::Debug for IssuingNetworkTokenDeviceType {
206 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
207 f.write_str(self.as_str())
208 }
209}
210#[cfg(feature = "redact-generated-debug")]
211impl std::fmt::Debug for IssuingNetworkTokenDeviceType {
212 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
213 f.debug_struct(stringify!(IssuingNetworkTokenDeviceType)).finish_non_exhaustive()
214 }
215}
216#[cfg(feature = "serialize")]
217impl serde::Serialize for IssuingNetworkTokenDeviceType {
218 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
219 where
220 S: serde::Serializer,
221 {
222 serializer.serialize_str(self.as_str())
223 }
224}
225impl miniserde::Deserialize for IssuingNetworkTokenDeviceType {
226 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
227 crate::Place::new(out)
228 }
229}
230
231impl miniserde::de::Visitor for crate::Place<IssuingNetworkTokenDeviceType> {
232 fn string(&mut self, s: &str) -> miniserde::Result<()> {
233 use std::str::FromStr;
234 self.out = Some(IssuingNetworkTokenDeviceType::from_str(s).expect("infallible"));
235 Ok(())
236 }
237}
238
239stripe_types::impl_from_val_with_from_str!(IssuingNetworkTokenDeviceType);
240#[cfg(feature = "deserialize")]
241impl<'de> serde::Deserialize<'de> for IssuingNetworkTokenDeviceType {
242 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
243 use std::str::FromStr;
244 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
245 Ok(Self::from_str(&s).expect("infallible"))
246 }
247}