stripe_shared/
application.rs1#[derive(Clone, Eq, PartialEq)]
2#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct Application {
5 pub id: stripe_shared::ApplicationId,
7 pub name: Option<String>,
9}
10#[cfg(feature = "redact-generated-debug")]
11impl std::fmt::Debug for Application {
12 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
13 f.debug_struct("Application").finish_non_exhaustive()
14 }
15}
16#[doc(hidden)]
17pub struct ApplicationBuilder {
18 id: Option<stripe_shared::ApplicationId>,
19 name: Option<Option<String>>,
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 Application {
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<Application>,
46 builder: ApplicationBuilder,
47 }
48
49 impl Visitor for Place<Application> {
50 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
51 Ok(Box::new(Builder {
52 out: &mut self.out,
53 builder: ApplicationBuilder::deser_default(),
54 }))
55 }
56 }
57
58 impl MapBuilder for ApplicationBuilder {
59 type Out = Application;
60 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
61 Ok(match k {
62 "id" => Deserialize::begin(&mut self.id),
63 "name" => Deserialize::begin(&mut self.name),
64 _ => <dyn Visitor>::ignore(),
65 })
66 }
67
68 fn deser_default() -> Self {
69 Self { id: None, name: Some(None) }
70 }
71
72 fn take_out(&mut self) -> Option<Self::Out> {
73 let (Some(id), Some(name)) = (self.id.take(), self.name.take()) else {
74 return None;
75 };
76 Some(Self::Out { id, name })
77 }
78 }
79
80 impl Map for Builder<'_> {
81 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
82 self.builder.key(k)
83 }
84
85 fn finish(&mut self) -> Result<()> {
86 *self.out = self.builder.take_out();
87 Ok(())
88 }
89 }
90
91 impl ObjectDeser for Application {
92 type Builder = ApplicationBuilder;
93 }
94
95 impl FromValueOpt for Application {
96 fn from_value(v: Value) -> Option<Self> {
97 let Value::Object(obj) = v else {
98 return None;
99 };
100 let mut b = ApplicationBuilder::deser_default();
101 for (k, v) in obj {
102 match k.as_str() {
103 "id" => b.id = FromValueOpt::from_value(v),
104 "name" => b.name = FromValueOpt::from_value(v),
105 _ => {}
106 }
107 }
108 b.take_out()
109 }
110 }
111};
112#[cfg(feature = "serialize")]
113impl serde::Serialize for Application {
114 fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
115 use serde::ser::SerializeStruct;
116 let mut s = s.serialize_struct("Application", 3)?;
117 s.serialize_field("id", &self.id)?;
118 s.serialize_field("name", &self.name)?;
119
120 s.serialize_field("object", "application")?;
121 s.end()
122 }
123}
124impl stripe_types::Object for Application {
125 type Id = stripe_shared::ApplicationId;
126 fn id(&self) -> &Self::Id {
127 &self.id
128 }
129
130 fn into_id(self) -> Self::Id {
131 self.id
132 }
133}
134stripe_types::def_id!(ApplicationId);