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 _ => <dyn Visitor>::ignore(),
64 })
65 }
66
67 fn deser_default() -> Self {
68 Self { amount: Deserialize::default(), currency: Deserialize::default() }
69 }
70
71 fn take_out(&mut self) -> Option<Self::Out> {
72 let (Some(amount), Some(currency)) = (self.amount, self.currency.take()) else {
73 return None;
74 };
75 Some(Self::Out { amount, currency })
76 }
77 }
78
79 impl Map for Builder<'_> {
80 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
81 self.builder.key(k)
82 }
83
84 fn finish(&mut self) -> Result<()> {
85 *self.out = self.builder.take_out();
86 Ok(())
87 }
88 }
89
90 impl ObjectDeser for TaxRateFlatAmount {
91 type Builder = TaxRateFlatAmountBuilder;
92 }
93
94 impl FromValueOpt for TaxRateFlatAmount {
95 fn from_value(v: Value) -> Option<Self> {
96 let Value::Object(obj) = v else {
97 return None;
98 };
99 let mut b = TaxRateFlatAmountBuilder::deser_default();
100 for (k, v) in obj {
101 match k.as_str() {
102 "amount" => b.amount = FromValueOpt::from_value(v),
103 "currency" => b.currency = FromValueOpt::from_value(v),
104 _ => {}
105 }
106 }
107 b.take_out()
108 }
109 }
110};