dropbox_sdk/generated/types/
account.rs

1// DO NOT EDIT
2// This file was @generated by Stone
3
4#![allow(
5    clippy::too_many_arguments,
6    clippy::large_enum_variant,
7    clippy::result_large_err,
8    clippy::doc_markdown,
9)]
10
11#[derive(Debug, Clone, PartialEq, Eq)]
12#[non_exhaustive] // variants may be added in the future
13pub enum PhotoSourceArg {
14    /// Image data in base64-encoded bytes.
15    Base64Data(String),
16    /// Catch-all used for unrecognized values returned from the server. Encountering this value
17    /// typically indicates that this SDK version is out of date.
18    Other,
19}
20
21impl<'de> ::serde::de::Deserialize<'de> for PhotoSourceArg {
22    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
23        // union deserializer
24        use serde::de::{self, MapAccess, Visitor};
25        struct EnumVisitor;
26        impl<'de> Visitor<'de> for EnumVisitor {
27            type Value = PhotoSourceArg;
28            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
29                f.write_str("a PhotoSourceArg structure")
30            }
31            fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> Result<Self::Value, V::Error> {
32                let tag: &str = match map.next_key()? {
33                    Some(".tag") => map.next_value()?,
34                    _ => return Err(de::Error::missing_field(".tag"))
35                };
36                let value = match tag {
37                    "base64_data" => {
38                        match map.next_key()? {
39                            Some("base64_data") => PhotoSourceArg::Base64Data(map.next_value()?),
40                            None => return Err(de::Error::missing_field("base64_data")),
41                            _ => return Err(de::Error::unknown_field(tag, VARIANTS))
42                        }
43                    }
44                    _ => PhotoSourceArg::Other,
45                };
46                crate::eat_json_fields(&mut map)?;
47                Ok(value)
48            }
49        }
50        const VARIANTS: &[&str] = &["base64_data",
51                                    "other"];
52        deserializer.deserialize_struct("PhotoSourceArg", VARIANTS, EnumVisitor)
53    }
54}
55
56impl ::serde::ser::Serialize for PhotoSourceArg {
57    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
58        // union serializer
59        use serde::ser::SerializeStruct;
60        match self {
61            PhotoSourceArg::Base64Data(x) => {
62                // primitive
63                let mut s = serializer.serialize_struct("PhotoSourceArg", 2)?;
64                s.serialize_field(".tag", "base64_data")?;
65                s.serialize_field("base64_data", x)?;
66                s.end()
67            }
68            PhotoSourceArg::Other => Err(::serde::ser::Error::custom("cannot serialize 'Other' variant"))
69        }
70    }
71}
72
73#[derive(Debug, Clone, PartialEq, Eq)]
74#[non_exhaustive] // structs may have more fields added in the future.
75pub struct SetProfilePhotoArg {
76    /// Image to set as the user's new profile photo.
77    pub photo: PhotoSourceArg,
78}
79
80impl SetProfilePhotoArg {
81    pub fn new(photo: PhotoSourceArg) -> Self {
82        SetProfilePhotoArg {
83            photo,
84        }
85    }
86}
87
88const SET_PROFILE_PHOTO_ARG_FIELDS: &[&str] = &["photo"];
89impl SetProfilePhotoArg {
90    pub(crate) fn internal_deserialize<'de, V: ::serde::de::MapAccess<'de>>(
91        map: V,
92    ) -> Result<SetProfilePhotoArg, V::Error> {
93        Self::internal_deserialize_opt(map, false).map(Option::unwrap)
94    }
95
96    pub(crate) fn internal_deserialize_opt<'de, V: ::serde::de::MapAccess<'de>>(
97        mut map: V,
98        optional: bool,
99    ) -> Result<Option<SetProfilePhotoArg>, V::Error> {
100        let mut field_photo = None;
101        let mut nothing = true;
102        while let Some(key) = map.next_key::<&str>()? {
103            nothing = false;
104            match key {
105                "photo" => {
106                    if field_photo.is_some() {
107                        return Err(::serde::de::Error::duplicate_field("photo"));
108                    }
109                    field_photo = Some(map.next_value()?);
110                }
111                _ => {
112                    // unknown field allowed and ignored
113                    map.next_value::<::serde_json::Value>()?;
114                }
115            }
116        }
117        if optional && nothing {
118            return Ok(None);
119        }
120        let result = SetProfilePhotoArg {
121            photo: field_photo.ok_or_else(|| ::serde::de::Error::missing_field("photo"))?,
122        };
123        Ok(Some(result))
124    }
125
126    pub(crate) fn internal_serialize<S: ::serde::ser::Serializer>(
127        &self,
128        s: &mut S::SerializeStruct,
129    ) -> Result<(), S::Error> {
130        use serde::ser::SerializeStruct;
131        s.serialize_field("photo", &self.photo)?;
132        Ok(())
133    }
134}
135
136impl<'de> ::serde::de::Deserialize<'de> for SetProfilePhotoArg {
137    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
138        // struct deserializer
139        use serde::de::{MapAccess, Visitor};
140        struct StructVisitor;
141        impl<'de> Visitor<'de> for StructVisitor {
142            type Value = SetProfilePhotoArg;
143            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
144                f.write_str("a SetProfilePhotoArg struct")
145            }
146            fn visit_map<V: MapAccess<'de>>(self, map: V) -> Result<Self::Value, V::Error> {
147                SetProfilePhotoArg::internal_deserialize(map)
148            }
149        }
150        deserializer.deserialize_struct("SetProfilePhotoArg", SET_PROFILE_PHOTO_ARG_FIELDS, StructVisitor)
151    }
152}
153
154impl ::serde::ser::Serialize for SetProfilePhotoArg {
155    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
156        // struct serializer
157        use serde::ser::SerializeStruct;
158        let mut s = serializer.serialize_struct("SetProfilePhotoArg", 1)?;
159        self.internal_serialize::<S>(&mut s)?;
160        s.end()
161    }
162}
163
164#[derive(Debug, Clone, PartialEq, Eq)]
165#[non_exhaustive] // variants may be added in the future
166pub enum SetProfilePhotoError {
167    /// File cannot be set as profile photo.
168    FileTypeError,
169    /// File cannot exceed 10 MB.
170    FileSizeError,
171    /// Image must be larger than 128 x 128.
172    DimensionError,
173    /// Image could not be thumbnailed.
174    ThumbnailError,
175    /// Temporary infrastructure failure, please retry.
176    TransientError,
177    /// Catch-all used for unrecognized values returned from the server. Encountering this value
178    /// typically indicates that this SDK version is out of date.
179    Other,
180}
181
182impl<'de> ::serde::de::Deserialize<'de> for SetProfilePhotoError {
183    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
184        // union deserializer
185        use serde::de::{self, MapAccess, Visitor};
186        struct EnumVisitor;
187        impl<'de> Visitor<'de> for EnumVisitor {
188            type Value = SetProfilePhotoError;
189            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
190                f.write_str("a SetProfilePhotoError structure")
191            }
192            fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> Result<Self::Value, V::Error> {
193                let tag: &str = match map.next_key()? {
194                    Some(".tag") => map.next_value()?,
195                    _ => return Err(de::Error::missing_field(".tag"))
196                };
197                let value = match tag {
198                    "file_type_error" => SetProfilePhotoError::FileTypeError,
199                    "file_size_error" => SetProfilePhotoError::FileSizeError,
200                    "dimension_error" => SetProfilePhotoError::DimensionError,
201                    "thumbnail_error" => SetProfilePhotoError::ThumbnailError,
202                    "transient_error" => SetProfilePhotoError::TransientError,
203                    _ => SetProfilePhotoError::Other,
204                };
205                crate::eat_json_fields(&mut map)?;
206                Ok(value)
207            }
208        }
209        const VARIANTS: &[&str] = &["file_type_error",
210                                    "file_size_error",
211                                    "dimension_error",
212                                    "thumbnail_error",
213                                    "transient_error",
214                                    "other"];
215        deserializer.deserialize_struct("SetProfilePhotoError", VARIANTS, EnumVisitor)
216    }
217}
218
219impl ::serde::ser::Serialize for SetProfilePhotoError {
220    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
221        // union serializer
222        use serde::ser::SerializeStruct;
223        match self {
224            SetProfilePhotoError::FileTypeError => {
225                // unit
226                let mut s = serializer.serialize_struct("SetProfilePhotoError", 1)?;
227                s.serialize_field(".tag", "file_type_error")?;
228                s.end()
229            }
230            SetProfilePhotoError::FileSizeError => {
231                // unit
232                let mut s = serializer.serialize_struct("SetProfilePhotoError", 1)?;
233                s.serialize_field(".tag", "file_size_error")?;
234                s.end()
235            }
236            SetProfilePhotoError::DimensionError => {
237                // unit
238                let mut s = serializer.serialize_struct("SetProfilePhotoError", 1)?;
239                s.serialize_field(".tag", "dimension_error")?;
240                s.end()
241            }
242            SetProfilePhotoError::ThumbnailError => {
243                // unit
244                let mut s = serializer.serialize_struct("SetProfilePhotoError", 1)?;
245                s.serialize_field(".tag", "thumbnail_error")?;
246                s.end()
247            }
248            SetProfilePhotoError::TransientError => {
249                // unit
250                let mut s = serializer.serialize_struct("SetProfilePhotoError", 1)?;
251                s.serialize_field(".tag", "transient_error")?;
252                s.end()
253            }
254            SetProfilePhotoError::Other => Err(::serde::ser::Error::custom("cannot serialize 'Other' variant"))
255        }
256    }
257}
258
259impl ::std::error::Error for SetProfilePhotoError {
260}
261
262impl ::std::fmt::Display for SetProfilePhotoError {
263    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
264        match self {
265            SetProfilePhotoError::FileTypeError => f.write_str("File cannot be set as profile photo."),
266            SetProfilePhotoError::FileSizeError => f.write_str("File cannot exceed 10 MB."),
267            SetProfilePhotoError::DimensionError => f.write_str("Image must be larger than 128 x 128."),
268            SetProfilePhotoError::ThumbnailError => f.write_str("Image could not be thumbnailed."),
269            SetProfilePhotoError::TransientError => f.write_str("Temporary infrastructure failure, please retry."),
270            _ => write!(f, "{:?}", *self),
271        }
272    }
273}
274
275#[derive(Debug, Clone, PartialEq, Eq)]
276#[non_exhaustive] // structs may have more fields added in the future.
277pub struct SetProfilePhotoResult {
278    /// URL for the photo representing the user, if one is set.
279    pub profile_photo_url: String,
280}
281
282impl SetProfilePhotoResult {
283    pub fn new(profile_photo_url: String) -> Self {
284        SetProfilePhotoResult {
285            profile_photo_url,
286        }
287    }
288}
289
290const SET_PROFILE_PHOTO_RESULT_FIELDS: &[&str] = &["profile_photo_url"];
291impl SetProfilePhotoResult {
292    pub(crate) fn internal_deserialize<'de, V: ::serde::de::MapAccess<'de>>(
293        map: V,
294    ) -> Result<SetProfilePhotoResult, V::Error> {
295        Self::internal_deserialize_opt(map, false).map(Option::unwrap)
296    }
297
298    pub(crate) fn internal_deserialize_opt<'de, V: ::serde::de::MapAccess<'de>>(
299        mut map: V,
300        optional: bool,
301    ) -> Result<Option<SetProfilePhotoResult>, V::Error> {
302        let mut field_profile_photo_url = None;
303        let mut nothing = true;
304        while let Some(key) = map.next_key::<&str>()? {
305            nothing = false;
306            match key {
307                "profile_photo_url" => {
308                    if field_profile_photo_url.is_some() {
309                        return Err(::serde::de::Error::duplicate_field("profile_photo_url"));
310                    }
311                    field_profile_photo_url = Some(map.next_value()?);
312                }
313                _ => {
314                    // unknown field allowed and ignored
315                    map.next_value::<::serde_json::Value>()?;
316                }
317            }
318        }
319        if optional && nothing {
320            return Ok(None);
321        }
322        let result = SetProfilePhotoResult {
323            profile_photo_url: field_profile_photo_url.ok_or_else(|| ::serde::de::Error::missing_field("profile_photo_url"))?,
324        };
325        Ok(Some(result))
326    }
327
328    pub(crate) fn internal_serialize<S: ::serde::ser::Serializer>(
329        &self,
330        s: &mut S::SerializeStruct,
331    ) -> Result<(), S::Error> {
332        use serde::ser::SerializeStruct;
333        s.serialize_field("profile_photo_url", &self.profile_photo_url)?;
334        Ok(())
335    }
336}
337
338impl<'de> ::serde::de::Deserialize<'de> for SetProfilePhotoResult {
339    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
340        // struct deserializer
341        use serde::de::{MapAccess, Visitor};
342        struct StructVisitor;
343        impl<'de> Visitor<'de> for StructVisitor {
344            type Value = SetProfilePhotoResult;
345            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
346                f.write_str("a SetProfilePhotoResult struct")
347            }
348            fn visit_map<V: MapAccess<'de>>(self, map: V) -> Result<Self::Value, V::Error> {
349                SetProfilePhotoResult::internal_deserialize(map)
350            }
351        }
352        deserializer.deserialize_struct("SetProfilePhotoResult", SET_PROFILE_PHOTO_RESULT_FIELDS, StructVisitor)
353    }
354}
355
356impl ::serde::ser::Serialize for SetProfilePhotoResult {
357    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
358        // struct serializer
359        use serde::ser::SerializeStruct;
360        let mut s = serializer.serialize_struct("SetProfilePhotoResult", 1)?;
361        self.internal_serialize::<S>(&mut s)?;
362        s.end()
363    }
364}
365