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