dropbox_sdk/generated/types/
common.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
11pub type Date = String /*Timestamp*/;
12pub type DisplayName = String;
13pub type DisplayNameLegacy = String;
14pub type DropboxTimestamp = String /*Timestamp*/;
15pub type EmailAddress = String;
16pub type LanguageCode = String;
17pub type NamePart = String;
18pub type NamespaceId = String;
19pub type OptionalNamePart = String;
20pub type SessionId = String;
21pub type SharedFolderId = NamespaceId;
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24#[non_exhaustive] // variants may be added in the future
25pub enum PathRoot {
26    /// Paths are relative to the authenticating user's home namespace, whether or not that user
27    /// belongs to a team.
28    Home,
29    /// Paths are relative to the authenticating user's root namespace (This results in
30    /// [`PathRootError::InvalidRoot`] if the user's root namespace has changed.).
31    Root(NamespaceId),
32    /// Paths are relative to given namespace id (This results in [`PathRootError::NoPermission`] if
33    /// you don't have access to this namespace.).
34    NamespaceId(NamespaceId),
35    /// Catch-all used for unrecognized values returned from the server. Encountering this value
36    /// typically indicates that this SDK version is out of date.
37    Other,
38}
39
40impl<'de> ::serde::de::Deserialize<'de> for PathRoot {
41    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
42        // union deserializer
43        use serde::de::{self, MapAccess, Visitor};
44        struct EnumVisitor;
45        impl<'de> Visitor<'de> for EnumVisitor {
46            type Value = PathRoot;
47            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
48                f.write_str("a PathRoot structure")
49            }
50            fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> Result<Self::Value, V::Error> {
51                let tag: &str = match map.next_key()? {
52                    Some(".tag") => map.next_value()?,
53                    _ => return Err(de::Error::missing_field(".tag"))
54                };
55                let value = match tag {
56                    "home" => PathRoot::Home,
57                    "root" => {
58                        match map.next_key()? {
59                            Some("root") => PathRoot::Root(map.next_value()?),
60                            None => return Err(de::Error::missing_field("root")),
61                            _ => return Err(de::Error::unknown_field(tag, VARIANTS))
62                        }
63                    }
64                    "namespace_id" => {
65                        match map.next_key()? {
66                            Some("namespace_id") => PathRoot::NamespaceId(map.next_value()?),
67                            None => return Err(de::Error::missing_field("namespace_id")),
68                            _ => return Err(de::Error::unknown_field(tag, VARIANTS))
69                        }
70                    }
71                    _ => PathRoot::Other,
72                };
73                crate::eat_json_fields(&mut map)?;
74                Ok(value)
75            }
76        }
77        const VARIANTS: &[&str] = &["home",
78                                    "root",
79                                    "namespace_id",
80                                    "other"];
81        deserializer.deserialize_struct("PathRoot", VARIANTS, EnumVisitor)
82    }
83}
84
85impl ::serde::ser::Serialize for PathRoot {
86    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
87        // union serializer
88        use serde::ser::SerializeStruct;
89        match self {
90            PathRoot::Home => {
91                // unit
92                let mut s = serializer.serialize_struct("PathRoot", 1)?;
93                s.serialize_field(".tag", "home")?;
94                s.end()
95            }
96            PathRoot::Root(x) => {
97                // primitive
98                let mut s = serializer.serialize_struct("PathRoot", 2)?;
99                s.serialize_field(".tag", "root")?;
100                s.serialize_field("root", x)?;
101                s.end()
102            }
103            PathRoot::NamespaceId(x) => {
104                // primitive
105                let mut s = serializer.serialize_struct("PathRoot", 2)?;
106                s.serialize_field(".tag", "namespace_id")?;
107                s.serialize_field("namespace_id", x)?;
108                s.end()
109            }
110            PathRoot::Other => Err(::serde::ser::Error::custom("cannot serialize 'Other' variant"))
111        }
112    }
113}
114
115#[derive(Debug, Clone, PartialEq, Eq)]
116#[non_exhaustive] // variants may be added in the future
117pub enum PathRootError {
118    /// The root namespace id in Dropbox-API-Path-Root header is not valid. The value of this error
119    /// is the user's latest root info.
120    InvalidRoot(RootInfo),
121    /// You don't have permission to access the namespace id in Dropbox-API-Path-Root  header.
122    NoPermission,
123    /// Catch-all used for unrecognized values returned from the server. Encountering this value
124    /// typically indicates that this SDK version is out of date.
125    Other,
126}
127
128impl<'de> ::serde::de::Deserialize<'de> for PathRootError {
129    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
130        // union deserializer
131        use serde::de::{self, MapAccess, Visitor};
132        struct EnumVisitor;
133        impl<'de> Visitor<'de> for EnumVisitor {
134            type Value = PathRootError;
135            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
136                f.write_str("a PathRootError structure")
137            }
138            fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> Result<Self::Value, V::Error> {
139                let tag: &str = match map.next_key()? {
140                    Some(".tag") => map.next_value()?,
141                    _ => return Err(de::Error::missing_field(".tag"))
142                };
143                let value = match tag {
144                    "invalid_root" => {
145                        match map.next_key()? {
146                            Some("invalid_root") => PathRootError::InvalidRoot(map.next_value()?),
147                            None => return Err(de::Error::missing_field("invalid_root")),
148                            _ => return Err(de::Error::unknown_field(tag, VARIANTS))
149                        }
150                    }
151                    "no_permission" => PathRootError::NoPermission,
152                    _ => PathRootError::Other,
153                };
154                crate::eat_json_fields(&mut map)?;
155                Ok(value)
156            }
157        }
158        const VARIANTS: &[&str] = &["invalid_root",
159                                    "no_permission",
160                                    "other"];
161        deserializer.deserialize_struct("PathRootError", VARIANTS, EnumVisitor)
162    }
163}
164
165impl ::serde::ser::Serialize for PathRootError {
166    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
167        // union serializer
168        use serde::ser::SerializeStruct;
169        match self {
170            PathRootError::InvalidRoot(x) => {
171                // union or polymporphic struct
172                let mut s = serializer.serialize_struct("PathRootError", 2)?;
173                s.serialize_field(".tag", "invalid_root")?;
174                s.serialize_field("invalid_root", x)?;
175                s.end()
176            }
177            PathRootError::NoPermission => {
178                // unit
179                let mut s = serializer.serialize_struct("PathRootError", 1)?;
180                s.serialize_field(".tag", "no_permission")?;
181                s.end()
182            }
183            PathRootError::Other => Err(::serde::ser::Error::custom("cannot serialize 'Other' variant"))
184        }
185    }
186}
187
188impl ::std::error::Error for PathRootError {
189}
190
191impl ::std::fmt::Display for PathRootError {
192    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
193        match self {
194            PathRootError::InvalidRoot(inner) => write!(f, "The root namespace id in Dropbox-API-Path-Root header is not valid. The value of this error is the user's latest root info: {:?}", inner),
195            PathRootError::NoPermission => f.write_str("You don't have permission to access the namespace id in Dropbox-API-Path-Root  header."),
196            _ => write!(f, "{:?}", *self),
197        }
198    }
199}
200
201/// Information about current user's root.
202#[derive(Debug, Clone, PartialEq, Eq)]
203#[non_exhaustive] // variants may be added in the future
204pub enum RootInfo {
205    Team(TeamRootInfo),
206    User(UserRootInfo),
207    /// Catch-all used for unrecognized values returned from the server. Encountering this value
208    /// typically indicates that this SDK version is out of date.
209    Other,
210}
211
212impl<'de> ::serde::de::Deserialize<'de> for RootInfo {
213    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
214        // polymorphic struct deserializer
215        use serde::de::{self, MapAccess, Visitor};
216        struct EnumVisitor;
217        impl<'de> Visitor<'de> for EnumVisitor {
218            type Value = RootInfo;
219            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
220                f.write_str("a RootInfo structure")
221            }
222            fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> Result<Self::Value, V::Error> {
223                let tag = match map.next_key()? {
224                    Some(".tag") => map.next_value()?,
225                    _ => return Err(de::Error::missing_field(".tag"))
226                };
227                match tag {
228                    "team" => Ok(RootInfo::Team(TeamRootInfo::internal_deserialize(map)?)),
229                    "user" => Ok(RootInfo::User(UserRootInfo::internal_deserialize(map)?)),
230                    _ => {
231                        crate::eat_json_fields(&mut map)?;
232                        Ok(RootInfo::Other)
233                    }
234                }
235            }
236        }
237        const VARIANTS: &[&str] = &["team",
238                                    "user"];
239        deserializer.deserialize_struct("RootInfo", VARIANTS, EnumVisitor)
240    }
241}
242
243impl ::serde::ser::Serialize for RootInfo {
244    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
245        // polymorphic struct serializer
246        use serde::ser::SerializeStruct;
247        match self {
248            RootInfo::Team(x) => {
249                let mut s = serializer.serialize_struct("RootInfo", 4)?;
250                s.serialize_field(".tag", "team")?;
251                x.internal_serialize::<S>(&mut s)?;
252                s.end()
253            }
254            RootInfo::User(x) => {
255                let mut s = serializer.serialize_struct("RootInfo", 3)?;
256                s.serialize_field(".tag", "user")?;
257                x.internal_serialize::<S>(&mut s)?;
258                s.end()
259            }
260            RootInfo::Other => Err(::serde::ser::Error::custom("cannot serialize unknown variant"))
261        }
262    }
263}
264
265/// Root info when user is member of a team with a separate root namespace ID.
266#[derive(Debug, Clone, PartialEq, Eq)]
267#[non_exhaustive] // structs may have more fields added in the future.
268pub struct TeamRootInfo {
269    /// The namespace ID for user's root namespace. It will be the namespace ID of the shared team
270    /// root if the user is member of a team with a separate team root. Otherwise it will be same as
271    /// `home_namespace_id`.
272    pub root_namespace_id: NamespaceId,
273    /// The namespace ID for user's home namespace.
274    pub home_namespace_id: NamespaceId,
275    /// The path for user's home directory under the shared team root.
276    pub home_path: String,
277}
278
279impl TeamRootInfo {
280    pub fn new(
281        root_namespace_id: NamespaceId,
282        home_namespace_id: NamespaceId,
283        home_path: String,
284    ) -> Self {
285        TeamRootInfo {
286            root_namespace_id,
287            home_namespace_id,
288            home_path,
289        }
290    }
291}
292
293const TEAM_ROOT_INFO_FIELDS: &[&str] = &["root_namespace_id",
294                                         "home_namespace_id",
295                                         "home_path"];
296impl TeamRootInfo {
297    pub(crate) fn internal_deserialize<'de, V: ::serde::de::MapAccess<'de>>(
298        map: V,
299    ) -> Result<TeamRootInfo, V::Error> {
300        Self::internal_deserialize_opt(map, false).map(Option::unwrap)
301    }
302
303    pub(crate) fn internal_deserialize_opt<'de, V: ::serde::de::MapAccess<'de>>(
304        mut map: V,
305        optional: bool,
306    ) -> Result<Option<TeamRootInfo>, V::Error> {
307        let mut field_root_namespace_id = None;
308        let mut field_home_namespace_id = None;
309        let mut field_home_path = None;
310        let mut nothing = true;
311        while let Some(key) = map.next_key::<&str>()? {
312            nothing = false;
313            match key {
314                "root_namespace_id" => {
315                    if field_root_namespace_id.is_some() {
316                        return Err(::serde::de::Error::duplicate_field("root_namespace_id"));
317                    }
318                    field_root_namespace_id = Some(map.next_value()?);
319                }
320                "home_namespace_id" => {
321                    if field_home_namespace_id.is_some() {
322                        return Err(::serde::de::Error::duplicate_field("home_namespace_id"));
323                    }
324                    field_home_namespace_id = Some(map.next_value()?);
325                }
326                "home_path" => {
327                    if field_home_path.is_some() {
328                        return Err(::serde::de::Error::duplicate_field("home_path"));
329                    }
330                    field_home_path = Some(map.next_value()?);
331                }
332                _ => {
333                    // unknown field allowed and ignored
334                    map.next_value::<::serde_json::Value>()?;
335                }
336            }
337        }
338        if optional && nothing {
339            return Ok(None);
340        }
341        let result = TeamRootInfo {
342            root_namespace_id: field_root_namespace_id.ok_or_else(|| ::serde::de::Error::missing_field("root_namespace_id"))?,
343            home_namespace_id: field_home_namespace_id.ok_or_else(|| ::serde::de::Error::missing_field("home_namespace_id"))?,
344            home_path: field_home_path.ok_or_else(|| ::serde::de::Error::missing_field("home_path"))?,
345        };
346        Ok(Some(result))
347    }
348
349    pub(crate) fn internal_serialize<S: ::serde::ser::Serializer>(
350        &self,
351        s: &mut S::SerializeStruct,
352    ) -> Result<(), S::Error> {
353        use serde::ser::SerializeStruct;
354        s.serialize_field("root_namespace_id", &self.root_namespace_id)?;
355        s.serialize_field("home_namespace_id", &self.home_namespace_id)?;
356        s.serialize_field("home_path", &self.home_path)?;
357        Ok(())
358    }
359}
360
361impl<'de> ::serde::de::Deserialize<'de> for TeamRootInfo {
362    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
363        // struct deserializer
364        use serde::de::{MapAccess, Visitor};
365        struct StructVisitor;
366        impl<'de> Visitor<'de> for StructVisitor {
367            type Value = TeamRootInfo;
368            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
369                f.write_str("a TeamRootInfo struct")
370            }
371            fn visit_map<V: MapAccess<'de>>(self, map: V) -> Result<Self::Value, V::Error> {
372                TeamRootInfo::internal_deserialize(map)
373            }
374        }
375        deserializer.deserialize_struct("TeamRootInfo", TEAM_ROOT_INFO_FIELDS, StructVisitor)
376    }
377}
378
379impl ::serde::ser::Serialize for TeamRootInfo {
380    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
381        // struct serializer
382        use serde::ser::SerializeStruct;
383        let mut s = serializer.serialize_struct("TeamRootInfo", 3)?;
384        self.internal_serialize::<S>(&mut s)?;
385        s.end()
386    }
387}
388
389// struct extends polymorphic struct RootInfo
390impl From<TeamRootInfo> for RootInfo {
391    fn from(subtype: TeamRootInfo) -> Self {
392        RootInfo::Team(subtype)
393    }
394}
395/// Root info when user is not member of a team or the user is a member of a team and the team does
396/// not have a separate root namespace.
397#[derive(Debug, Clone, PartialEq, Eq)]
398#[non_exhaustive] // structs may have more fields added in the future.
399pub struct UserRootInfo {
400    /// The namespace ID for user's root namespace. It will be the namespace ID of the shared team
401    /// root if the user is member of a team with a separate team root. Otherwise it will be same as
402    /// `home_namespace_id`.
403    pub root_namespace_id: NamespaceId,
404    /// The namespace ID for user's home namespace.
405    pub home_namespace_id: NamespaceId,
406}
407
408impl UserRootInfo {
409    pub fn new(root_namespace_id: NamespaceId, home_namespace_id: NamespaceId) -> Self {
410        UserRootInfo {
411            root_namespace_id,
412            home_namespace_id,
413        }
414    }
415}
416
417const USER_ROOT_INFO_FIELDS: &[&str] = &["root_namespace_id",
418                                         "home_namespace_id"];
419impl UserRootInfo {
420    pub(crate) fn internal_deserialize<'de, V: ::serde::de::MapAccess<'de>>(
421        map: V,
422    ) -> Result<UserRootInfo, V::Error> {
423        Self::internal_deserialize_opt(map, false).map(Option::unwrap)
424    }
425
426    pub(crate) fn internal_deserialize_opt<'de, V: ::serde::de::MapAccess<'de>>(
427        mut map: V,
428        optional: bool,
429    ) -> Result<Option<UserRootInfo>, V::Error> {
430        let mut field_root_namespace_id = None;
431        let mut field_home_namespace_id = None;
432        let mut nothing = true;
433        while let Some(key) = map.next_key::<&str>()? {
434            nothing = false;
435            match key {
436                "root_namespace_id" => {
437                    if field_root_namespace_id.is_some() {
438                        return Err(::serde::de::Error::duplicate_field("root_namespace_id"));
439                    }
440                    field_root_namespace_id = Some(map.next_value()?);
441                }
442                "home_namespace_id" => {
443                    if field_home_namespace_id.is_some() {
444                        return Err(::serde::de::Error::duplicate_field("home_namespace_id"));
445                    }
446                    field_home_namespace_id = Some(map.next_value()?);
447                }
448                _ => {
449                    // unknown field allowed and ignored
450                    map.next_value::<::serde_json::Value>()?;
451                }
452            }
453        }
454        if optional && nothing {
455            return Ok(None);
456        }
457        let result = UserRootInfo {
458            root_namespace_id: field_root_namespace_id.ok_or_else(|| ::serde::de::Error::missing_field("root_namespace_id"))?,
459            home_namespace_id: field_home_namespace_id.ok_or_else(|| ::serde::de::Error::missing_field("home_namespace_id"))?,
460        };
461        Ok(Some(result))
462    }
463
464    pub(crate) fn internal_serialize<S: ::serde::ser::Serializer>(
465        &self,
466        s: &mut S::SerializeStruct,
467    ) -> Result<(), S::Error> {
468        use serde::ser::SerializeStruct;
469        s.serialize_field("root_namespace_id", &self.root_namespace_id)?;
470        s.serialize_field("home_namespace_id", &self.home_namespace_id)?;
471        Ok(())
472    }
473}
474
475impl<'de> ::serde::de::Deserialize<'de> for UserRootInfo {
476    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
477        // struct deserializer
478        use serde::de::{MapAccess, Visitor};
479        struct StructVisitor;
480        impl<'de> Visitor<'de> for StructVisitor {
481            type Value = UserRootInfo;
482            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
483                f.write_str("a UserRootInfo struct")
484            }
485            fn visit_map<V: MapAccess<'de>>(self, map: V) -> Result<Self::Value, V::Error> {
486                UserRootInfo::internal_deserialize(map)
487            }
488        }
489        deserializer.deserialize_struct("UserRootInfo", USER_ROOT_INFO_FIELDS, StructVisitor)
490    }
491}
492
493impl ::serde::ser::Serialize for UserRootInfo {
494    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
495        // struct serializer
496        use serde::ser::SerializeStruct;
497        let mut s = serializer.serialize_struct("UserRootInfo", 2)?;
498        self.internal_serialize::<S>(&mut s)?;
499        s.end()
500    }
501}
502
503// struct extends polymorphic struct RootInfo
504impl From<UserRootInfo> for RootInfo {
505    fn from(subtype: UserRootInfo) -> Self {
506        RootInfo::User(subtype)
507    }
508}