stripe_shared/
tax_rate_flat_amount.rs1#[derive(Clone, Debug)]
5#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
6#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
7pub struct TaxRateFlatAmount {
8 pub amount: i64,
12 pub currency: stripe_types::Currency,
14}
15#[doc(hidden)]
16pub struct TaxRateFlatAmountBuilder {
17 amount: Option<i64>,
18 currency: Option<stripe_types::Currency>,
19}
20
21#[allow(
22 unused_variables,
23 irrefutable_let_patterns,
24 clippy::let_unit_value,
25 clippy::match_single_binding,
26 clippy::single_match
27)]
28const _: () = {
29 use miniserde::de::{Map, Visitor};
30 use miniserde::json::Value;
31 use miniserde::{Deserialize, Result, make_place};
32 use stripe_types::miniserde_helpers::FromValueOpt;
33 use stripe_types::{MapBuilder, ObjectDeser};
34
35 make_place!(Place);
36
37 impl Deserialize for TaxRateFlatAmount {
38 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
39 Place::new(out)
40 }
41 }
42
43 struct Builder<'a> {
44 out: &'a mut Option<TaxRateFlatAmount>,
45 builder: TaxRateFlatAmountBuilder,
46 }
47
48 impl Visitor for Place<TaxRateFlatAmount> {
49 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
50 Ok(Box::new(Builder {
51 out: &mut self.out,
52 builder: TaxRateFlatAmountBuilder::deser_default(),
53 }))
54 }
55 }
56
57 impl MapBuilder for TaxRateFlatAmountBuilder {
58 type Out = TaxRateFlatAmount;
59 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
60 Ok(match k {
61 "amount" => Deserialize::begin(&mut self.amount),
62 "currency" => Deserialize::begin(&mut self.currency),
63
64 _ => <dyn Visitor>::ignore(),
65 })
66 }
67
68 fn deser_default() -> Self {
69 Self { amount: Deserialize::default(), currency: Deserialize::default() }
70 }
71
72 fn take_out(&mut self) -> Option<Self::Out> {
73 let (Some(amount), Some(currency)) = (self.amount, self.currency.take()) else {
74 return None;
75 };
76 Some(Self::Out { amount, currency })
77 }
78 }
79
80 impl Map for Builder<'_> {
81 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
82 self.builder.key(k)
83 }
84
85 fn finish(&mut self) -> Result<()> {
86 *self.out = self.builder.take_out();
87 Ok(())
88 }
89 }
90
91 impl ObjectDeser for TaxRateFlatAmount {
92 type Builder = TaxRateFlatAmountBuilder;
93 }
94
95 impl FromValueOpt for TaxRateFlatAmount {
96 fn from_value(v: Value) -> Option<Self> {
97 let Value::Object(obj) = v else {
98 return None;
99 };
100 let mut b = TaxRateFlatAmountBuilder::deser_default();
101 for (k, v) in obj {
102 match k.as_str() {
103 "amount" => b.amount = FromValueOpt::from_value(v),
104 "currency" => b.currency = FromValueOpt::from_value(v),
105
106 _ => {}
107 }
108 }
109 b.take_out()
110 }
111 }
112};