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 Fee {
6 pub amount: i64,
8 pub application: Option<String>,
10 pub currency: stripe_types::Currency,
13 pub description: Option<String>,
15 #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
17 pub type_: String,
18}
19#[cfg(feature = "redact-generated-debug")]
20impl std::fmt::Debug for Fee {
21 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
22 f.debug_struct("Fee").finish_non_exhaustive()
23 }
24}
25#[doc(hidden)]
26pub struct FeeBuilder {
27 amount: Option<i64>,
28 application: Option<Option<String>>,
29 currency: Option<stripe_types::Currency>,
30 description: Option<Option<String>>,
31 type_: Option<String>,
32}
33
34#[allow(
35 unused_variables,
36 irrefutable_let_patterns,
37 clippy::let_unit_value,
38 clippy::match_single_binding,
39 clippy::single_match
40)]
41const _: () = {
42 use miniserde::de::{Map, Visitor};
43 use miniserde::json::Value;
44 use miniserde::{Deserialize, Result, make_place};
45 use stripe_types::miniserde_helpers::FromValueOpt;
46 use stripe_types::{MapBuilder, ObjectDeser};
47
48 make_place!(Place);
49
50 impl Deserialize for Fee {
51 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
52 Place::new(out)
53 }
54 }
55
56 struct Builder<'a> {
57 out: &'a mut Option<Fee>,
58 builder: FeeBuilder,
59 }
60
61 impl Visitor for Place<Fee> {
62 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
63 Ok(Box::new(Builder { out: &mut self.out, builder: FeeBuilder::deser_default() }))
64 }
65 }
66
67 impl MapBuilder for FeeBuilder {
68 type Out = Fee;
69 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
70 Ok(match k {
71 "amount" => Deserialize::begin(&mut self.amount),
72 "application" => Deserialize::begin(&mut self.application),
73 "currency" => Deserialize::begin(&mut self.currency),
74 "description" => Deserialize::begin(&mut self.description),
75 "type" => Deserialize::begin(&mut self.type_),
76 _ => <dyn Visitor>::ignore(),
77 })
78 }
79
80 fn deser_default() -> Self {
81 Self {
82 amount: None,
83 application: Some(None),
84 currency: None,
85 description: Some(None),
86 type_: None,
87 }
88 }
89
90 fn take_out(&mut self) -> Option<Self::Out> {
91 let (Some(amount), Some(application), Some(currency), Some(description), Some(type_)) = (
92 self.amount,
93 self.application.take(),
94 self.currency.take(),
95 self.description.take(),
96 self.type_.take(),
97 ) else {
98 return None;
99 };
100 Some(Self::Out { amount, application, currency, description, type_ })
101 }
102 }
103
104 impl Map for Builder<'_> {
105 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
106 self.builder.key(k)
107 }
108
109 fn finish(&mut self) -> Result<()> {
110 *self.out = self.builder.take_out();
111 Ok(())
112 }
113 }
114
115 impl ObjectDeser for Fee {
116 type Builder = FeeBuilder;
117 }
118
119 impl FromValueOpt for Fee {
120 fn from_value(v: Value) -> Option<Self> {
121 let Value::Object(obj) = v else {
122 return None;
123 };
124 let mut b = FeeBuilder::deser_default();
125 for (k, v) in obj {
126 match k.as_str() {
127 "amount" => b.amount = FromValueOpt::from_value(v),
128 "application" => b.application = FromValueOpt::from_value(v),
129 "currency" => b.currency = FromValueOpt::from_value(v),
130 "description" => b.description = FromValueOpt::from_value(v),
131 "type" => b.type_ = FromValueOpt::from_value(v),
132 _ => {}
133 }
134 }
135 b.take_out()
136 }
137 }
138};