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