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