Skip to main content

stripe_shared/
discounts_resource_stackable_discount_with_discount_end.rs

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