stripe_shared/
subscription_schedules_resource_invoice_item_period_resource_period_start.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStart {
5    /// A precise Unix timestamp for the start of the invoice item period.
6    /// Must be less than or equal to `period.end`.
7    pub timestamp: Option<stripe_types::Timestamp>,
8    /// Select how to calculate the start of the invoice item period.
9    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
10    pub type_: SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStartType,
11}
12#[doc(hidden)]
13pub struct SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStartBuilder {
14    timestamp: Option<Option<stripe_types::Timestamp>>,
15    type_: Option<SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStartType>,
16}
17
18#[allow(
19    unused_variables,
20    irrefutable_let_patterns,
21    clippy::let_unit_value,
22    clippy::match_single_binding,
23    clippy::single_match
24)]
25const _: () = {
26    use miniserde::de::{Map, Visitor};
27    use miniserde::json::Value;
28    use miniserde::{Deserialize, Result, make_place};
29    use stripe_types::miniserde_helpers::FromValueOpt;
30    use stripe_types::{MapBuilder, ObjectDeser};
31
32    make_place!(Place);
33
34    impl Deserialize for SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStart {
35        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
36            Place::new(out)
37        }
38    }
39
40    struct Builder<'a> {
41        out: &'a mut Option<SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStart>,
42        builder: SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStartBuilder,
43    }
44
45    impl Visitor for Place<SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStart> {
46        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
47            Ok(Box::new(Builder {
48            out: &mut self.out,
49            builder: SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStartBuilder::deser_default(),
50        }))
51        }
52    }
53
54    impl MapBuilder for SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStartBuilder {
55        type Out = SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStart;
56        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
57            Ok(match k {
58                "timestamp" => Deserialize::begin(&mut self.timestamp),
59                "type" => Deserialize::begin(&mut self.type_),
60                _ => <dyn Visitor>::ignore(),
61            })
62        }
63
64        fn deser_default() -> Self {
65            Self { timestamp: Deserialize::default(), type_: Deserialize::default() }
66        }
67
68        fn take_out(&mut self) -> Option<Self::Out> {
69            let (Some(timestamp), Some(type_)) = (self.timestamp, self.type_.take()) else {
70                return None;
71            };
72            Some(Self::Out { timestamp, type_ })
73        }
74    }
75
76    impl Map for Builder<'_> {
77        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
78            self.builder.key(k)
79        }
80
81        fn finish(&mut self) -> Result<()> {
82            *self.out = self.builder.take_out();
83            Ok(())
84        }
85    }
86
87    impl ObjectDeser for SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStart {
88        type Builder = SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStartBuilder;
89    }
90
91    impl FromValueOpt for SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStart {
92        fn from_value(v: Value) -> Option<Self> {
93            let Value::Object(obj) = v else {
94                return None;
95            };
96            let mut b = SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStartBuilder::deser_default();
97            for (k, v) in obj {
98                match k.as_str() {
99                    "timestamp" => b.timestamp = FromValueOpt::from_value(v),
100                    "type" => b.type_ = FromValueOpt::from_value(v),
101                    _ => {}
102                }
103            }
104            b.take_out()
105        }
106    }
107};
108/// Select how to calculate the start of the invoice item period.
109#[derive(Clone, Eq, PartialEq)]
110#[non_exhaustive]
111pub enum SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStartType {
112    MaxItemPeriodStart,
113    PhaseStart,
114    Timestamp,
115    /// An unrecognized value from Stripe. Should not be used as a request parameter.
116    Unknown(String),
117}
118impl SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStartType {
119    pub fn as_str(&self) -> &str {
120        use SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStartType::*;
121        match self {
122            MaxItemPeriodStart => "max_item_period_start",
123            PhaseStart => "phase_start",
124            Timestamp => "timestamp",
125            Unknown(v) => v,
126        }
127    }
128}
129
130impl std::str::FromStr for SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStartType {
131    type Err = std::convert::Infallible;
132    fn from_str(s: &str) -> Result<Self, Self::Err> {
133        use SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStartType::*;
134        match s {
135            "max_item_period_start" => Ok(MaxItemPeriodStart),
136            "phase_start" => Ok(PhaseStart),
137            "timestamp" => Ok(Timestamp),
138            v => {
139                tracing::warn!(
140                    "Unknown value '{}' for enum '{}'",
141                    v,
142                    "SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStartType"
143                );
144                Ok(Unknown(v.to_owned()))
145            }
146        }
147    }
148}
149impl std::fmt::Display for SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStartType {
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 SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStartType {
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 SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStartType {
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
170    for SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStartType
171{
172    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
173        crate::Place::new(out)
174    }
175}
176
177impl miniserde::de::Visitor
178    for crate::Place<SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStartType>
179{
180    fn string(&mut self, s: &str) -> miniserde::Result<()> {
181        use std::str::FromStr;
182        self.out = Some(
183            SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStartType::from_str(s)
184                .expect("infallible"),
185        );
186        Ok(())
187    }
188}
189
190stripe_types::impl_from_val_with_from_str!(
191    SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStartType
192);
193#[cfg(feature = "deserialize")]
194impl<'de> serde::Deserialize<'de>
195    for SubscriptionSchedulesResourceInvoiceItemPeriodResourcePeriodStartType
196{
197    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
198        use std::str::FromStr;
199        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
200        Ok(Self::from_str(&s).expect("infallible"))
201    }
202}