stripe_shared/
shipping_rate_currency_option.rs1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct ShippingRateCurrencyOption {
5 pub amount: i64,
7 pub tax_behavior: ShippingRateCurrencyOptionTaxBehavior,
10}
11#[doc(hidden)]
12pub struct ShippingRateCurrencyOptionBuilder {
13 amount: Option<i64>,
14 tax_behavior: Option<ShippingRateCurrencyOptionTaxBehavior>,
15}
16
17#[allow(
18 unused_variables,
19 irrefutable_let_patterns,
20 clippy::let_unit_value,
21 clippy::match_single_binding,
22 clippy::single_match
23)]
24const _: () = {
25 use miniserde::de::{Map, Visitor};
26 use miniserde::json::Value;
27 use miniserde::{Deserialize, Result, make_place};
28 use stripe_types::miniserde_helpers::FromValueOpt;
29 use stripe_types::{MapBuilder, ObjectDeser};
30
31 make_place!(Place);
32
33 impl Deserialize for ShippingRateCurrencyOption {
34 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
35 Place::new(out)
36 }
37 }
38
39 struct Builder<'a> {
40 out: &'a mut Option<ShippingRateCurrencyOption>,
41 builder: ShippingRateCurrencyOptionBuilder,
42 }
43
44 impl Visitor for Place<ShippingRateCurrencyOption> {
45 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
46 Ok(Box::new(Builder {
47 out: &mut self.out,
48 builder: ShippingRateCurrencyOptionBuilder::deser_default(),
49 }))
50 }
51 }
52
53 impl MapBuilder for ShippingRateCurrencyOptionBuilder {
54 type Out = ShippingRateCurrencyOption;
55 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
56 Ok(match k {
57 "amount" => Deserialize::begin(&mut self.amount),
58 "tax_behavior" => Deserialize::begin(&mut self.tax_behavior),
59 _ => <dyn Visitor>::ignore(),
60 })
61 }
62
63 fn deser_default() -> Self {
64 Self { amount: Deserialize::default(), tax_behavior: Deserialize::default() }
65 }
66
67 fn take_out(&mut self) -> Option<Self::Out> {
68 let (Some(amount), Some(tax_behavior)) = (self.amount, self.tax_behavior.take()) else {
69 return None;
70 };
71 Some(Self::Out { amount, tax_behavior })
72 }
73 }
74
75 impl Map for Builder<'_> {
76 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
77 self.builder.key(k)
78 }
79
80 fn finish(&mut self) -> Result<()> {
81 *self.out = self.builder.take_out();
82 Ok(())
83 }
84 }
85
86 impl ObjectDeser for ShippingRateCurrencyOption {
87 type Builder = ShippingRateCurrencyOptionBuilder;
88 }
89
90 impl FromValueOpt for ShippingRateCurrencyOption {
91 fn from_value(v: Value) -> Option<Self> {
92 let Value::Object(obj) = v else {
93 return None;
94 };
95 let mut b = ShippingRateCurrencyOptionBuilder::deser_default();
96 for (k, v) in obj {
97 match k.as_str() {
98 "amount" => b.amount = FromValueOpt::from_value(v),
99 "tax_behavior" => b.tax_behavior = FromValueOpt::from_value(v),
100 _ => {}
101 }
102 }
103 b.take_out()
104 }
105 }
106};
107#[derive(Clone, Eq, PartialEq)]
110#[non_exhaustive]
111pub enum ShippingRateCurrencyOptionTaxBehavior {
112 Exclusive,
113 Inclusive,
114 Unspecified,
115 Unknown(String),
117}
118impl ShippingRateCurrencyOptionTaxBehavior {
119 pub fn as_str(&self) -> &str {
120 use ShippingRateCurrencyOptionTaxBehavior::*;
121 match self {
122 Exclusive => "exclusive",
123 Inclusive => "inclusive",
124 Unspecified => "unspecified",
125 Unknown(v) => v,
126 }
127 }
128}
129
130impl std::str::FromStr for ShippingRateCurrencyOptionTaxBehavior {
131 type Err = std::convert::Infallible;
132 fn from_str(s: &str) -> Result<Self, Self::Err> {
133 use ShippingRateCurrencyOptionTaxBehavior::*;
134 match s {
135 "exclusive" => Ok(Exclusive),
136 "inclusive" => Ok(Inclusive),
137 "unspecified" => Ok(Unspecified),
138 v => {
139 tracing::warn!(
140 "Unknown value '{}' for enum '{}'",
141 v,
142 "ShippingRateCurrencyOptionTaxBehavior"
143 );
144 Ok(Unknown(v.to_owned()))
145 }
146 }
147 }
148}
149impl std::fmt::Display for ShippingRateCurrencyOptionTaxBehavior {
150 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
151 f.write_str(self.as_str())
152 }
153}
154
155impl std::fmt::Debug for ShippingRateCurrencyOptionTaxBehavior {
156 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
157 f.write_str(self.as_str())
158 }
159}
160#[cfg(feature = "serialize")]
161impl serde::Serialize for ShippingRateCurrencyOptionTaxBehavior {
162 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
163 where
164 S: serde::Serializer,
165 {
166 serializer.serialize_str(self.as_str())
167 }
168}
169impl miniserde::Deserialize for ShippingRateCurrencyOptionTaxBehavior {
170 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
171 crate::Place::new(out)
172 }
173}
174
175impl miniserde::de::Visitor for crate::Place<ShippingRateCurrencyOptionTaxBehavior> {
176 fn string(&mut self, s: &str) -> miniserde::Result<()> {
177 use std::str::FromStr;
178 self.out = Some(ShippingRateCurrencyOptionTaxBehavior::from_str(s).expect("infallible"));
179 Ok(())
180 }
181}
182
183stripe_types::impl_from_val_with_from_str!(ShippingRateCurrencyOptionTaxBehavior);
184#[cfg(feature = "deserialize")]
185impl<'de> serde::Deserialize<'de> for ShippingRateCurrencyOptionTaxBehavior {
186 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
187 use std::str::FromStr;
188 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
189 Ok(Self::from_str(&s).expect("infallible"))
190 }
191}