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