stripe_shared/
payment_pages_checkout_session_shipping_option.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 PaymentPagesCheckoutSessionShippingOption {
6 pub shipping_amount: i64,
8 pub shipping_rate: stripe_types::Expandable<stripe_shared::ShippingRate>,
10}
11#[cfg(feature = "redact-generated-debug")]
12impl std::fmt::Debug for PaymentPagesCheckoutSessionShippingOption {
13 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
14 f.debug_struct("PaymentPagesCheckoutSessionShippingOption").finish_non_exhaustive()
15 }
16}
17#[doc(hidden)]
18pub struct PaymentPagesCheckoutSessionShippingOptionBuilder {
19 shipping_amount: Option<i64>,
20 shipping_rate: Option<stripe_types::Expandable<stripe_shared::ShippingRate>>,
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 PaymentPagesCheckoutSessionShippingOption {
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<PaymentPagesCheckoutSessionShippingOption>,
47 builder: PaymentPagesCheckoutSessionShippingOptionBuilder,
48 }
49
50 impl Visitor for Place<PaymentPagesCheckoutSessionShippingOption> {
51 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
52 Ok(Box::new(Builder {
53 out: &mut self.out,
54 builder: PaymentPagesCheckoutSessionShippingOptionBuilder::deser_default(),
55 }))
56 }
57 }
58
59 impl MapBuilder for PaymentPagesCheckoutSessionShippingOptionBuilder {
60 type Out = PaymentPagesCheckoutSessionShippingOption;
61 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
62 Ok(match k {
63 "shipping_amount" => Deserialize::begin(&mut self.shipping_amount),
64 "shipping_rate" => Deserialize::begin(&mut self.shipping_rate),
65 _ => <dyn Visitor>::ignore(),
66 })
67 }
68
69 fn deser_default() -> Self {
70 Self { shipping_amount: None, shipping_rate: None }
71 }
72
73 fn take_out(&mut self) -> Option<Self::Out> {
74 let (Some(shipping_amount), Some(shipping_rate)) =
75 (self.shipping_amount, self.shipping_rate.take())
76 else {
77 return None;
78 };
79 Some(Self::Out { shipping_amount, shipping_rate })
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 PaymentPagesCheckoutSessionShippingOption {
95 type Builder = PaymentPagesCheckoutSessionShippingOptionBuilder;
96 }
97
98 impl FromValueOpt for PaymentPagesCheckoutSessionShippingOption {
99 fn from_value(v: Value) -> Option<Self> {
100 let Value::Object(obj) = v else {
101 return None;
102 };
103 let mut b = PaymentPagesCheckoutSessionShippingOptionBuilder::deser_default();
104 for (k, v) in obj {
105 match k.as_str() {
106 "shipping_amount" => b.shipping_amount = FromValueOpt::from_value(v),
107 "shipping_rate" => b.shipping_rate = FromValueOpt::from_value(v),
108 _ => {}
109 }
110 }
111 b.take_out()
112 }
113 }
114};