stripe_shared/
source_order_item.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct SourceOrderItem {
5    /// The amount (price) for this order item.
6    pub amount: Option<i64>,
7    /// This currency of this order item. Required when `amount` is present.
8    pub currency: Option<stripe_types::Currency>,
9    /// Human-readable description for this order item.
10    pub description: Option<String>,
11    /// The ID of the associated object for this line item.
12    /// Expandable if not null (e.g., expandable to a SKU).
13    pub parent: Option<String>,
14    /// The quantity of this order item.
15    /// When type is `sku`, this is the number of instances of the SKU to be ordered.
16    pub quantity: Option<u64>,
17    /// The type of this order item. Must be `sku`, `tax`, or `shipping`.
18    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
19    pub type_: Option<String>,
20}
21#[doc(hidden)]
22pub struct SourceOrderItemBuilder {
23    amount: Option<Option<i64>>,
24    currency: Option<Option<stripe_types::Currency>>,
25    description: Option<Option<String>>,
26    parent: Option<Option<String>>,
27    quantity: Option<Option<u64>>,
28    type_: Option<Option<String>>,
29}
30
31#[allow(
32    unused_variables,
33    irrefutable_let_patterns,
34    clippy::let_unit_value,
35    clippy::match_single_binding,
36    clippy::single_match
37)]
38const _: () = {
39    use miniserde::de::{Map, Visitor};
40    use miniserde::json::Value;
41    use miniserde::{make_place, Deserialize, Result};
42    use stripe_types::miniserde_helpers::FromValueOpt;
43    use stripe_types::{MapBuilder, ObjectDeser};
44
45    make_place!(Place);
46
47    impl Deserialize for SourceOrderItem {
48        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
49            Place::new(out)
50        }
51    }
52
53    struct Builder<'a> {
54        out: &'a mut Option<SourceOrderItem>,
55        builder: SourceOrderItemBuilder,
56    }
57
58    impl Visitor for Place<SourceOrderItem> {
59        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
60            Ok(Box::new(Builder {
61                out: &mut self.out,
62                builder: SourceOrderItemBuilder::deser_default(),
63            }))
64        }
65    }
66
67    impl MapBuilder for SourceOrderItemBuilder {
68        type Out = SourceOrderItem;
69        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
70            Ok(match k {
71                "amount" => Deserialize::begin(&mut self.amount),
72                "currency" => Deserialize::begin(&mut self.currency),
73                "description" => Deserialize::begin(&mut self.description),
74                "parent" => Deserialize::begin(&mut self.parent),
75                "quantity" => Deserialize::begin(&mut self.quantity),
76                "type" => Deserialize::begin(&mut self.type_),
77
78                _ => <dyn Visitor>::ignore(),
79            })
80        }
81
82        fn deser_default() -> Self {
83            Self {
84                amount: Deserialize::default(),
85                currency: Deserialize::default(),
86                description: Deserialize::default(),
87                parent: Deserialize::default(),
88                quantity: Deserialize::default(),
89                type_: Deserialize::default(),
90            }
91        }
92
93        fn take_out(&mut self) -> Option<Self::Out> {
94            let (
95                Some(amount),
96                Some(currency),
97                Some(description),
98                Some(parent),
99                Some(quantity),
100                Some(type_),
101            ) = (
102                self.amount,
103                self.currency,
104                self.description.take(),
105                self.parent.take(),
106                self.quantity,
107                self.type_.take(),
108            )
109            else {
110                return None;
111            };
112            Some(Self::Out { amount, currency, description, parent, quantity, type_ })
113        }
114    }
115
116    impl<'a> Map for Builder<'a> {
117        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
118            self.builder.key(k)
119        }
120
121        fn finish(&mut self) -> Result<()> {
122            *self.out = self.builder.take_out();
123            Ok(())
124        }
125    }
126
127    impl ObjectDeser for SourceOrderItem {
128        type Builder = SourceOrderItemBuilder;
129    }
130
131    impl FromValueOpt for SourceOrderItem {
132        fn from_value(v: Value) -> Option<Self> {
133            let Value::Object(obj) = v else {
134                return None;
135            };
136            let mut b = SourceOrderItemBuilder::deser_default();
137            for (k, v) in obj {
138                match k.as_str() {
139                    "amount" => b.amount = FromValueOpt::from_value(v),
140                    "currency" => b.currency = FromValueOpt::from_value(v),
141                    "description" => b.description = FromValueOpt::from_value(v),
142                    "parent" => b.parent = FromValueOpt::from_value(v),
143                    "quantity" => b.quantity = FromValueOpt::from_value(v),
144                    "type" => b.type_ = FromValueOpt::from_value(v),
145
146                    _ => {}
147                }
148            }
149            b.take_out()
150        }
151    }
152};