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