stripe_shared/
application.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
3pub struct Application {
4    /// Unique identifier for the object.
5    pub id: stripe_shared::ApplicationId,
6    /// The name of the application.
7    pub name: Option<String>,
8}
9#[doc(hidden)]
10pub struct ApplicationBuilder {
11    id: Option<stripe_shared::ApplicationId>,
12    name: Option<Option<String>>,
13}
14
15#[allow(
16    unused_variables,
17    irrefutable_let_patterns,
18    clippy::let_unit_value,
19    clippy::match_single_binding,
20    clippy::single_match
21)]
22const _: () = {
23    use miniserde::de::{Map, Visitor};
24    use miniserde::json::Value;
25    use miniserde::{make_place, Deserialize, Result};
26    use stripe_types::miniserde_helpers::FromValueOpt;
27    use stripe_types::{MapBuilder, ObjectDeser};
28
29    make_place!(Place);
30
31    impl Deserialize for Application {
32        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
33            Place::new(out)
34        }
35    }
36
37    struct Builder<'a> {
38        out: &'a mut Option<Application>,
39        builder: ApplicationBuilder,
40    }
41
42    impl Visitor for Place<Application> {
43        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
44            Ok(Box::new(Builder {
45                out: &mut self.out,
46                builder: ApplicationBuilder::deser_default(),
47            }))
48        }
49    }
50
51    impl MapBuilder for ApplicationBuilder {
52        type Out = Application;
53        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
54            Ok(match k {
55                "id" => Deserialize::begin(&mut self.id),
56                "name" => Deserialize::begin(&mut self.name),
57
58                _ => <dyn Visitor>::ignore(),
59            })
60        }
61
62        fn deser_default() -> Self {
63            Self { id: Deserialize::default(), name: Deserialize::default() }
64        }
65
66        fn take_out(&mut self) -> Option<Self::Out> {
67            let (Some(id), Some(name)) = (self.id.take(), self.name.take()) else {
68                return None;
69            };
70            Some(Self::Out { id, name })
71        }
72    }
73
74    impl<'a> Map for Builder<'a> {
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 Application {
86        type Builder = ApplicationBuilder;
87    }
88
89    impl FromValueOpt for Application {
90        fn from_value(v: Value) -> Option<Self> {
91            let Value::Object(obj) = v else {
92                return None;
93            };
94            let mut b = ApplicationBuilder::deser_default();
95            for (k, v) in obj {
96                match k.as_str() {
97                    "id" => b.id = FromValueOpt::from_value(v),
98                    "name" => b.name = FromValueOpt::from_value(v),
99
100                    _ => {}
101                }
102            }
103            b.take_out()
104        }
105    }
106};
107#[cfg(feature = "serialize")]
108impl serde::Serialize for Application {
109    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
110        use serde::ser::SerializeStruct;
111        let mut s = s.serialize_struct("Application", 3)?;
112        s.serialize_field("id", &self.id)?;
113        s.serialize_field("name", &self.name)?;
114
115        s.serialize_field("object", "application")?;
116        s.end()
117    }
118}
119impl stripe_types::Object for Application {
120    type Id = stripe_shared::ApplicationId;
121    fn id(&self) -> &Self::Id {
122        &self.id
123    }
124
125    fn into_id(self) -> Self::Id {
126        self.id
127    }
128}
129stripe_types::def_id!(ApplicationId);