stripe_shared/
invoices_resource_invoice_rendering.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct InvoicesResourceInvoiceRendering {
5    /// How line-item prices and amounts will be displayed with respect to tax on invoice PDFs.
6    pub amount_tax_display: Option<String>,
7    /// Invoice pdf rendering options
8    pub pdf: Option<stripe_shared::InvoiceRenderingPdf>,
9    /// ID of the rendering template that the invoice is formatted by.
10    pub template: Option<String>,
11    /// Version of the rendering template that the invoice is using.
12    pub template_version: Option<i64>,
13}
14#[doc(hidden)]
15pub struct InvoicesResourceInvoiceRenderingBuilder {
16    amount_tax_display: Option<Option<String>>,
17    pdf: Option<Option<stripe_shared::InvoiceRenderingPdf>>,
18    template: Option<Option<String>>,
19    template_version: Option<Option<i64>>,
20}
21
22#[allow(
23    unused_variables,
24    irrefutable_let_patterns,
25    clippy::let_unit_value,
26    clippy::match_single_binding,
27    clippy::single_match
28)]
29const _: () = {
30    use miniserde::de::{Map, Visitor};
31    use miniserde::json::Value;
32    use miniserde::{Deserialize, Result, make_place};
33    use stripe_types::miniserde_helpers::FromValueOpt;
34    use stripe_types::{MapBuilder, ObjectDeser};
35
36    make_place!(Place);
37
38    impl Deserialize for InvoicesResourceInvoiceRendering {
39        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
40            Place::new(out)
41        }
42    }
43
44    struct Builder<'a> {
45        out: &'a mut Option<InvoicesResourceInvoiceRendering>,
46        builder: InvoicesResourceInvoiceRenderingBuilder,
47    }
48
49    impl Visitor for Place<InvoicesResourceInvoiceRendering> {
50        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
51            Ok(Box::new(Builder {
52                out: &mut self.out,
53                builder: InvoicesResourceInvoiceRenderingBuilder::deser_default(),
54            }))
55        }
56    }
57
58    impl MapBuilder for InvoicesResourceInvoiceRenderingBuilder {
59        type Out = InvoicesResourceInvoiceRendering;
60        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
61            Ok(match k {
62                "amount_tax_display" => Deserialize::begin(&mut self.amount_tax_display),
63                "pdf" => Deserialize::begin(&mut self.pdf),
64                "template" => Deserialize::begin(&mut self.template),
65                "template_version" => Deserialize::begin(&mut self.template_version),
66
67                _ => <dyn Visitor>::ignore(),
68            })
69        }
70
71        fn deser_default() -> Self {
72            Self {
73                amount_tax_display: Deserialize::default(),
74                pdf: Deserialize::default(),
75                template: Deserialize::default(),
76                template_version: Deserialize::default(),
77            }
78        }
79
80        fn take_out(&mut self) -> Option<Self::Out> {
81            let (Some(amount_tax_display), Some(pdf), Some(template), Some(template_version)) = (
82                self.amount_tax_display.take(),
83                self.pdf,
84                self.template.take(),
85                self.template_version,
86            ) else {
87                return None;
88            };
89            Some(Self::Out { amount_tax_display, pdf, template, template_version })
90        }
91    }
92
93    impl Map for Builder<'_> {
94        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
95            self.builder.key(k)
96        }
97
98        fn finish(&mut self) -> Result<()> {
99            *self.out = self.builder.take_out();
100            Ok(())
101        }
102    }
103
104    impl ObjectDeser for InvoicesResourceInvoiceRendering {
105        type Builder = InvoicesResourceInvoiceRenderingBuilder;
106    }
107
108    impl FromValueOpt for InvoicesResourceInvoiceRendering {
109        fn from_value(v: Value) -> Option<Self> {
110            let Value::Object(obj) = v else {
111                return None;
112            };
113            let mut b = InvoicesResourceInvoiceRenderingBuilder::deser_default();
114            for (k, v) in obj {
115                match k.as_str() {
116                    "amount_tax_display" => b.amount_tax_display = FromValueOpt::from_value(v),
117                    "pdf" => b.pdf = FromValueOpt::from_value(v),
118                    "template" => b.template = FromValueOpt::from_value(v),
119                    "template_version" => b.template_version = FromValueOpt::from_value(v),
120
121                    _ => {}
122                }
123            }
124            b.take_out()
125        }
126    }
127};