Skip to main content

dropbox_sdk/generated/types/
auth.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    clippy::doc_lazy_continuation,
10)]
11
12/// Error occurred because the account doesn't have permission to access the resource.
13#[derive(Debug, Clone, PartialEq, Eq)]
14#[non_exhaustive] // variants may be added in the future
15pub enum AccessError {
16    /// Current account type cannot access the resource.
17    InvalidAccountType(InvalidAccountTypeError),
18    /// Current account cannot access Paper.
19    PaperAccessDenied(PaperAccessError),
20    /// Team doesn't have permission to access.
21    TeamAccessDenied,
22    /// Caller does not have permission to access the resource.
23    NoPermission(NoPermissionError),
24    /// Catch-all used for unrecognized values returned from the server. Encountering this value
25    /// typically indicates that this SDK version is out of date.
26    Other,
27}
28
29impl<'de> ::serde::de::Deserialize<'de> for AccessError {
30    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
31        // union deserializer
32        use serde::de::{self, MapAccess, Visitor};
33        struct EnumVisitor;
34        impl<'de> Visitor<'de> for EnumVisitor {
35            type Value = AccessError;
36            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
37                f.write_str("a AccessError structure")
38            }
39            fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> Result<Self::Value, V::Error> {
40                let tag: &str = match map.next_key()? {
41                    Some(".tag") => map.next_value()?,
42                    _ => return Err(de::Error::missing_field(".tag"))
43                };
44                let value = match tag {
45                    "invalid_account_type" => {
46                        match map.next_key()? {
47                            Some("invalid_account_type") => AccessError::InvalidAccountType(map.next_value()?),
48                            None => return Err(de::Error::missing_field("invalid_account_type")),
49                            _ => return Err(de::Error::unknown_field(tag, VARIANTS))
50                        }
51                    }
52                    "paper_access_denied" => {
53                        match map.next_key()? {
54                            Some("paper_access_denied") => AccessError::PaperAccessDenied(map.next_value()?),
55                            None => return Err(de::Error::missing_field("paper_access_denied")),
56                            _ => return Err(de::Error::unknown_field(tag, VARIANTS))
57                        }
58                    }
59                    "team_access_denied" => AccessError::TeamAccessDenied,
60                    "no_permission" => {
61                        match map.next_key()? {
62                            Some("no_permission") => AccessError::NoPermission(map.next_value()?),
63                            None => return Err(de::Error::missing_field("no_permission")),
64                            _ => return Err(de::Error::unknown_field(tag, VARIANTS))
65                        }
66                    }
67                    _ => AccessError::Other,
68                };
69                crate::eat_json_fields(&mut map)?;
70                Ok(value)
71            }
72        }
73        const VARIANTS: &[&str] = &["invalid_account_type",
74                                    "paper_access_denied",
75                                    "team_access_denied",
76                                    "no_permission",
77                                    "other"];
78        deserializer.deserialize_struct("AccessError", VARIANTS, EnumVisitor)
79    }
80}
81
82impl ::serde::ser::Serialize for AccessError {
83    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
84        // union serializer
85        use serde::ser::SerializeStruct;
86        match self {
87            AccessError::InvalidAccountType(x) => {
88                // union or polymporphic struct
89                let mut s = serializer.serialize_struct("AccessError", 2)?;
90                s.serialize_field(".tag", "invalid_account_type")?;
91                s.serialize_field("invalid_account_type", x)?;
92                s.end()
93            }
94            AccessError::PaperAccessDenied(x) => {
95                // union or polymporphic struct
96                let mut s = serializer.serialize_struct("AccessError", 2)?;
97                s.serialize_field(".tag", "paper_access_denied")?;
98                s.serialize_field("paper_access_denied", x)?;
99                s.end()
100            }
101            AccessError::TeamAccessDenied => {
102                // unit
103                let mut s = serializer.serialize_struct("AccessError", 1)?;
104                s.serialize_field(".tag", "team_access_denied")?;
105                s.end()
106            }
107            AccessError::NoPermission(x) => {
108                // union or polymporphic struct
109                let mut s = serializer.serialize_struct("AccessError", 2)?;
110                s.serialize_field(".tag", "no_permission")?;
111                s.serialize_field("no_permission", x)?;
112                s.end()
113            }
114            AccessError::Other => Err(::serde::ser::Error::custom("cannot serialize 'Other' variant"))
115        }
116    }
117}
118
119impl ::std::error::Error for AccessError {
120    fn source(&self) -> Option<&(dyn ::std::error::Error + 'static)> {
121        match self {
122            AccessError::InvalidAccountType(inner) => Some(inner),
123            AccessError::PaperAccessDenied(inner) => Some(inner),
124            AccessError::NoPermission(inner) => Some(inner),
125            _ => None,
126        }
127    }
128}
129
130impl ::std::fmt::Display for AccessError {
131    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
132        match self {
133            AccessError::InvalidAccountType(inner) => write!(f, "Current account type cannot access the resource: {}", inner),
134            AccessError::PaperAccessDenied(inner) => write!(f, "Current account cannot access Paper: {}", inner),
135            AccessError::TeamAccessDenied => f.write_str("Team doesn't have permission to access."),
136            AccessError::NoPermission(inner) => write!(f, "Caller does not have permission to access the resource: {}", inner),
137            _ => write!(f, "{:?}", *self),
138        }
139    }
140}
141
142/// Errors occurred during authentication.
143#[derive(Debug, Clone, PartialEq, Eq)]
144#[non_exhaustive] // variants may be added in the future
145pub enum AuthError {
146    /// The access token is invalid.
147    InvalidAccessToken,
148    /// The user specified in 'Dropbox-API-Select-User' is no longer on the team.
149    InvalidSelectUser,
150    /// The user specified in 'Dropbox-API-Select-Admin' is not a Dropbox Business team admin.
151    InvalidSelectAdmin,
152    /// The user has been suspended.
153    UserSuspended,
154    /// The access token has expired.
155    ExpiredAccessToken,
156    /// The access token does not have the required scope to access the route.
157    MissingScope(TokenScopeError),
158    /// The route is not available to public.
159    RouteAccessDenied,
160    /// Catch-all used for unrecognized values returned from the server. Encountering this value
161    /// typically indicates that this SDK version is out of date.
162    Other,
163}
164
165impl<'de> ::serde::de::Deserialize<'de> for AuthError {
166    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
167        // union deserializer
168        use serde::de::{self, MapAccess, Visitor};
169        struct EnumVisitor;
170        impl<'de> Visitor<'de> for EnumVisitor {
171            type Value = AuthError;
172            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
173                f.write_str("a AuthError structure")
174            }
175            fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> Result<Self::Value, V::Error> {
176                let tag: &str = match map.next_key()? {
177                    Some(".tag") => map.next_value()?,
178                    _ => return Err(de::Error::missing_field(".tag"))
179                };
180                let value = match tag {
181                    "invalid_access_token" => AuthError::InvalidAccessToken,
182                    "invalid_select_user" => AuthError::InvalidSelectUser,
183                    "invalid_select_admin" => AuthError::InvalidSelectAdmin,
184                    "user_suspended" => AuthError::UserSuspended,
185                    "expired_access_token" => AuthError::ExpiredAccessToken,
186                    "missing_scope" => AuthError::MissingScope(TokenScopeError::internal_deserialize(&mut map)?),
187                    "route_access_denied" => AuthError::RouteAccessDenied,
188                    _ => AuthError::Other,
189                };
190                crate::eat_json_fields(&mut map)?;
191                Ok(value)
192            }
193        }
194        const VARIANTS: &[&str] = &["invalid_access_token",
195                                    "invalid_select_user",
196                                    "invalid_select_admin",
197                                    "user_suspended",
198                                    "expired_access_token",
199                                    "missing_scope",
200                                    "route_access_denied",
201                                    "other"];
202        deserializer.deserialize_struct("AuthError", VARIANTS, EnumVisitor)
203    }
204}
205
206impl ::serde::ser::Serialize for AuthError {
207    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
208        // union serializer
209        use serde::ser::SerializeStruct;
210        match self {
211            AuthError::InvalidAccessToken => {
212                // unit
213                let mut s = serializer.serialize_struct("AuthError", 1)?;
214                s.serialize_field(".tag", "invalid_access_token")?;
215                s.end()
216            }
217            AuthError::InvalidSelectUser => {
218                // unit
219                let mut s = serializer.serialize_struct("AuthError", 1)?;
220                s.serialize_field(".tag", "invalid_select_user")?;
221                s.end()
222            }
223            AuthError::InvalidSelectAdmin => {
224                // unit
225                let mut s = serializer.serialize_struct("AuthError", 1)?;
226                s.serialize_field(".tag", "invalid_select_admin")?;
227                s.end()
228            }
229            AuthError::UserSuspended => {
230                // unit
231                let mut s = serializer.serialize_struct("AuthError", 1)?;
232                s.serialize_field(".tag", "user_suspended")?;
233                s.end()
234            }
235            AuthError::ExpiredAccessToken => {
236                // unit
237                let mut s = serializer.serialize_struct("AuthError", 1)?;
238                s.serialize_field(".tag", "expired_access_token")?;
239                s.end()
240            }
241            AuthError::MissingScope(x) => {
242                // struct
243                let mut s = serializer.serialize_struct("AuthError", 2)?;
244                s.serialize_field(".tag", "missing_scope")?;
245                x.internal_serialize::<S>(&mut s)?;
246                s.end()
247            }
248            AuthError::RouteAccessDenied => {
249                // unit
250                let mut s = serializer.serialize_struct("AuthError", 1)?;
251                s.serialize_field(".tag", "route_access_denied")?;
252                s.end()
253            }
254            AuthError::Other => Err(::serde::ser::Error::custom("cannot serialize 'Other' variant"))
255        }
256    }
257}
258
259impl ::std::error::Error for AuthError {
260}
261
262impl ::std::fmt::Display for AuthError {
263    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
264        match self {
265            AuthError::InvalidAccessToken => f.write_str("The access token is invalid."),
266            AuthError::InvalidSelectUser => f.write_str("The user specified in 'Dropbox-API-Select-User' is no longer on the team."),
267            AuthError::InvalidSelectAdmin => f.write_str("The user specified in 'Dropbox-API-Select-Admin' is not a Dropbox Business team admin."),
268            AuthError::UserSuspended => f.write_str("The user has been suspended."),
269            AuthError::ExpiredAccessToken => f.write_str("The access token has expired."),
270            AuthError::MissingScope(inner) => write!(f, "The access token does not have the required scope to access the route: {:?}", inner),
271            AuthError::RouteAccessDenied => f.write_str("The route is not available to public."),
272            _ => write!(f, "{:?}", *self),
273        }
274    }
275}
276
277#[derive(Debug, Clone, PartialEq, Eq)]
278#[non_exhaustive] // variants may be added in the future
279pub enum InvalidAccountTypeError {
280    /// Current account type doesn't have permission to access this route endpoint.
281    Endpoint,
282    /// Current account type doesn't have permission to access this feature.
283    Feature,
284    /// Catch-all used for unrecognized values returned from the server. Encountering this value
285    /// typically indicates that this SDK version is out of date.
286    Other,
287}
288
289impl<'de> ::serde::de::Deserialize<'de> for InvalidAccountTypeError {
290    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
291        // union deserializer
292        use serde::de::{self, MapAccess, Visitor};
293        struct EnumVisitor;
294        impl<'de> Visitor<'de> for EnumVisitor {
295            type Value = InvalidAccountTypeError;
296            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
297                f.write_str("a InvalidAccountTypeError structure")
298            }
299            fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> Result<Self::Value, V::Error> {
300                let tag: &str = match map.next_key()? {
301                    Some(".tag") => map.next_value()?,
302                    _ => return Err(de::Error::missing_field(".tag"))
303                };
304                let value = match tag {
305                    "endpoint" => InvalidAccountTypeError::Endpoint,
306                    "feature" => InvalidAccountTypeError::Feature,
307                    _ => InvalidAccountTypeError::Other,
308                };
309                crate::eat_json_fields(&mut map)?;
310                Ok(value)
311            }
312        }
313        const VARIANTS: &[&str] = &["endpoint",
314                                    "feature",
315                                    "other"];
316        deserializer.deserialize_struct("InvalidAccountTypeError", VARIANTS, EnumVisitor)
317    }
318}
319
320impl ::serde::ser::Serialize for InvalidAccountTypeError {
321    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
322        // union serializer
323        use serde::ser::SerializeStruct;
324        match self {
325            InvalidAccountTypeError::Endpoint => {
326                // unit
327                let mut s = serializer.serialize_struct("InvalidAccountTypeError", 1)?;
328                s.serialize_field(".tag", "endpoint")?;
329                s.end()
330            }
331            InvalidAccountTypeError::Feature => {
332                // unit
333                let mut s = serializer.serialize_struct("InvalidAccountTypeError", 1)?;
334                s.serialize_field(".tag", "feature")?;
335                s.end()
336            }
337            InvalidAccountTypeError::Other => Err(::serde::ser::Error::custom("cannot serialize 'Other' variant"))
338        }
339    }
340}
341
342impl ::std::error::Error for InvalidAccountTypeError {
343}
344
345impl ::std::fmt::Display for InvalidAccountTypeError {
346    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
347        match self {
348            InvalidAccountTypeError::Endpoint => f.write_str("Current account type doesn't have permission to access this route endpoint."),
349            InvalidAccountTypeError::Feature => f.write_str("Current account type doesn't have permission to access this feature."),
350            _ => write!(f, "{:?}", *self),
351        }
352    }
353}
354
355#[derive(Debug, Clone, PartialEq, Eq)]
356#[non_exhaustive] // variants may be added in the future
357pub enum NoPermissionError {
358    /// Current caller does not have permission to access the account information for one or more of
359    /// the specified account IDs.
360    UnauthorizedAccountIdUsage(UnauthorizedAccountIdUsageError),
361    /// Catch-all used for unrecognized values returned from the server. Encountering this value
362    /// typically indicates that this SDK version is out of date.
363    Other,
364}
365
366impl<'de> ::serde::de::Deserialize<'de> for NoPermissionError {
367    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
368        // union deserializer
369        use serde::de::{self, MapAccess, Visitor};
370        struct EnumVisitor;
371        impl<'de> Visitor<'de> for EnumVisitor {
372            type Value = NoPermissionError;
373            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
374                f.write_str("a NoPermissionError structure")
375            }
376            fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> Result<Self::Value, V::Error> {
377                let tag: &str = match map.next_key()? {
378                    Some(".tag") => map.next_value()?,
379                    _ => return Err(de::Error::missing_field(".tag"))
380                };
381                let value = match tag {
382                    "unauthorized_account_id_usage" => NoPermissionError::UnauthorizedAccountIdUsage(UnauthorizedAccountIdUsageError::internal_deserialize(&mut map)?),
383                    _ => NoPermissionError::Other,
384                };
385                crate::eat_json_fields(&mut map)?;
386                Ok(value)
387            }
388        }
389        const VARIANTS: &[&str] = &["unauthorized_account_id_usage",
390                                    "other"];
391        deserializer.deserialize_struct("NoPermissionError", VARIANTS, EnumVisitor)
392    }
393}
394
395impl ::serde::ser::Serialize for NoPermissionError {
396    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
397        // union serializer
398        use serde::ser::SerializeStruct;
399        match self {
400            NoPermissionError::UnauthorizedAccountIdUsage(x) => {
401                // struct
402                let mut s = serializer.serialize_struct("NoPermissionError", 2)?;
403                s.serialize_field(".tag", "unauthorized_account_id_usage")?;
404                x.internal_serialize::<S>(&mut s)?;
405                s.end()
406            }
407            NoPermissionError::Other => Err(::serde::ser::Error::custom("cannot serialize 'Other' variant"))
408        }
409    }
410}
411
412impl ::std::error::Error for NoPermissionError {
413}
414
415impl ::std::fmt::Display for NoPermissionError {
416    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
417        match self {
418            NoPermissionError::UnauthorizedAccountIdUsage(inner) => write!(f, "Current caller does not have permission to access the account information for one or more of the specified account IDs: {:?}", inner),
419            _ => write!(f, "{:?}", *self),
420        }
421    }
422}
423
424#[derive(Debug, Clone, PartialEq, Eq)]
425#[non_exhaustive] // variants may be added in the future
426pub enum PaperAccessError {
427    /// Paper is disabled.
428    PaperDisabled,
429    /// The provided user has not used Paper yet.
430    NotPaperUser,
431    /// Catch-all used for unrecognized values returned from the server. Encountering this value
432    /// typically indicates that this SDK version is out of date.
433    Other,
434}
435
436impl<'de> ::serde::de::Deserialize<'de> for PaperAccessError {
437    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
438        // union deserializer
439        use serde::de::{self, MapAccess, Visitor};
440        struct EnumVisitor;
441        impl<'de> Visitor<'de> for EnumVisitor {
442            type Value = PaperAccessError;
443            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
444                f.write_str("a PaperAccessError structure")
445            }
446            fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> Result<Self::Value, V::Error> {
447                let tag: &str = match map.next_key()? {
448                    Some(".tag") => map.next_value()?,
449                    _ => return Err(de::Error::missing_field(".tag"))
450                };
451                let value = match tag {
452                    "paper_disabled" => PaperAccessError::PaperDisabled,
453                    "not_paper_user" => PaperAccessError::NotPaperUser,
454                    _ => PaperAccessError::Other,
455                };
456                crate::eat_json_fields(&mut map)?;
457                Ok(value)
458            }
459        }
460        const VARIANTS: &[&str] = &["paper_disabled",
461                                    "not_paper_user",
462                                    "other"];
463        deserializer.deserialize_struct("PaperAccessError", VARIANTS, EnumVisitor)
464    }
465}
466
467impl ::serde::ser::Serialize for PaperAccessError {
468    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
469        // union serializer
470        use serde::ser::SerializeStruct;
471        match self {
472            PaperAccessError::PaperDisabled => {
473                // unit
474                let mut s = serializer.serialize_struct("PaperAccessError", 1)?;
475                s.serialize_field(".tag", "paper_disabled")?;
476                s.end()
477            }
478            PaperAccessError::NotPaperUser => {
479                // unit
480                let mut s = serializer.serialize_struct("PaperAccessError", 1)?;
481                s.serialize_field(".tag", "not_paper_user")?;
482                s.end()
483            }
484            PaperAccessError::Other => Err(::serde::ser::Error::custom("cannot serialize 'Other' variant"))
485        }
486    }
487}
488
489impl ::std::error::Error for PaperAccessError {
490}
491
492impl ::std::fmt::Display for PaperAccessError {
493    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
494        match self {
495            PaperAccessError::PaperDisabled => f.write_str("Paper is disabled."),
496            PaperAccessError::NotPaperUser => f.write_str("The provided user has not used Paper yet."),
497            _ => write!(f, "{:?}", *self),
498        }
499    }
500}
501
502/// Error occurred because the app is being rate limited.
503#[derive(Debug, Clone, PartialEq, Eq)]
504#[non_exhaustive] // structs may have more fields added in the future.
505pub struct RateLimitError {
506    /// The reason why the app is being rate limited.
507    pub reason: RateLimitReason,
508    /// The number of seconds that the app should wait before making another request.
509    pub retry_after: u64,
510}
511
512impl RateLimitError {
513    pub fn new(reason: RateLimitReason) -> Self {
514        RateLimitError {
515            reason,
516            retry_after: 1,
517        }
518    }
519
520    pub fn with_retry_after(mut self, value: u64) -> Self {
521        self.retry_after = value;
522        self
523    }
524}
525
526const RATE_LIMIT_ERROR_FIELDS: &[&str] = &["reason",
527                                           "retry_after"];
528impl RateLimitError {
529    pub(crate) fn internal_deserialize<'de, V: ::serde::de::MapAccess<'de>>(
530        map: V,
531    ) -> Result<RateLimitError, V::Error> {
532        Self::internal_deserialize_opt(map, false).map(Option::unwrap)
533    }
534
535    pub(crate) fn internal_deserialize_opt<'de, V: ::serde::de::MapAccess<'de>>(
536        mut map: V,
537        optional: bool,
538    ) -> Result<Option<RateLimitError>, V::Error> {
539        let mut field_reason = None;
540        let mut field_retry_after = None;
541        let mut nothing = true;
542        while let Some(key) = map.next_key::<&str>()? {
543            nothing = false;
544            match key {
545                "reason" => {
546                    if field_reason.is_some() {
547                        return Err(::serde::de::Error::duplicate_field("reason"));
548                    }
549                    field_reason = Some(map.next_value()?);
550                }
551                "retry_after" => {
552                    if field_retry_after.is_some() {
553                        return Err(::serde::de::Error::duplicate_field("retry_after"));
554                    }
555                    field_retry_after = Some(map.next_value()?);
556                }
557                _ => {
558                    // unknown field allowed and ignored
559                    map.next_value::<::serde_json::Value>()?;
560                }
561            }
562        }
563        if optional && nothing {
564            return Ok(None);
565        }
566        let result = RateLimitError {
567            reason: field_reason.ok_or_else(|| ::serde::de::Error::missing_field("reason"))?,
568            retry_after: field_retry_after.unwrap_or(1),
569        };
570        Ok(Some(result))
571    }
572
573    pub(crate) fn internal_serialize<S: ::serde::ser::Serializer>(
574        &self,
575        s: &mut S::SerializeStruct,
576    ) -> Result<(), S::Error> {
577        use serde::ser::SerializeStruct;
578        s.serialize_field("reason", &self.reason)?;
579        if self.retry_after != 1 {
580            s.serialize_field("retry_after", &self.retry_after)?;
581        }
582        Ok(())
583    }
584}
585
586impl<'de> ::serde::de::Deserialize<'de> for RateLimitError {
587    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
588        // struct deserializer
589        use serde::de::{MapAccess, Visitor};
590        struct StructVisitor;
591        impl<'de> Visitor<'de> for StructVisitor {
592            type Value = RateLimitError;
593            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
594                f.write_str("a RateLimitError struct")
595            }
596            fn visit_map<V: MapAccess<'de>>(self, map: V) -> Result<Self::Value, V::Error> {
597                RateLimitError::internal_deserialize(map)
598            }
599        }
600        deserializer.deserialize_struct("RateLimitError", RATE_LIMIT_ERROR_FIELDS, StructVisitor)
601    }
602}
603
604impl ::serde::ser::Serialize for RateLimitError {
605    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
606        // struct serializer
607        use serde::ser::SerializeStruct;
608        let mut s = serializer.serialize_struct("RateLimitError", 2)?;
609        self.internal_serialize::<S>(&mut s)?;
610        s.end()
611    }
612}
613
614#[derive(Debug, Clone, PartialEq, Eq)]
615#[non_exhaustive] // variants may be added in the future
616pub enum RateLimitReason {
617    /// You are making too many requests in the past few minutes.
618    TooManyRequests,
619    /// There are currently too many write operations happening in the user's Dropbox.
620    TooManyWriteOperations,
621    /// Catch-all used for unrecognized values returned from the server. Encountering this value
622    /// typically indicates that this SDK version is out of date.
623    Other,
624}
625
626impl<'de> ::serde::de::Deserialize<'de> for RateLimitReason {
627    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
628        // union deserializer
629        use serde::de::{self, MapAccess, Visitor};
630        struct EnumVisitor;
631        impl<'de> Visitor<'de> for EnumVisitor {
632            type Value = RateLimitReason;
633            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
634                f.write_str("a RateLimitReason structure")
635            }
636            fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> Result<Self::Value, V::Error> {
637                let tag: &str = match map.next_key()? {
638                    Some(".tag") => map.next_value()?,
639                    _ => return Err(de::Error::missing_field(".tag"))
640                };
641                let value = match tag {
642                    "too_many_requests" => RateLimitReason::TooManyRequests,
643                    "too_many_write_operations" => RateLimitReason::TooManyWriteOperations,
644                    _ => RateLimitReason::Other,
645                };
646                crate::eat_json_fields(&mut map)?;
647                Ok(value)
648            }
649        }
650        const VARIANTS: &[&str] = &["too_many_requests",
651                                    "too_many_write_operations",
652                                    "other"];
653        deserializer.deserialize_struct("RateLimitReason", VARIANTS, EnumVisitor)
654    }
655}
656
657impl ::serde::ser::Serialize for RateLimitReason {
658    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
659        // union serializer
660        use serde::ser::SerializeStruct;
661        match self {
662            RateLimitReason::TooManyRequests => {
663                // unit
664                let mut s = serializer.serialize_struct("RateLimitReason", 1)?;
665                s.serialize_field(".tag", "too_many_requests")?;
666                s.end()
667            }
668            RateLimitReason::TooManyWriteOperations => {
669                // unit
670                let mut s = serializer.serialize_struct("RateLimitReason", 1)?;
671                s.serialize_field(".tag", "too_many_write_operations")?;
672                s.end()
673            }
674            RateLimitReason::Other => Err(::serde::ser::Error::custom("cannot serialize 'Other' variant"))
675        }
676    }
677}
678
679impl ::std::fmt::Display for RateLimitReason {
680    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
681        match self {
682            RateLimitReason::TooManyRequests => f.write_str("You are making too many requests in the past few minutes."),
683            RateLimitReason::TooManyWriteOperations => f.write_str("There are currently too many write operations happening in the user's Dropbox."),
684            _ => write!(f, "{:?}", *self),
685        }
686    }
687}
688
689#[derive(Debug, Clone, PartialEq, Eq)]
690#[non_exhaustive] // structs may have more fields added in the future.
691pub struct TokenFromOAuth1Arg {
692    /// The supplied OAuth 1.0 access token.
693    pub oauth1_token: String,
694    /// The token secret associated with the supplied access token.
695    pub oauth1_token_secret: String,
696}
697
698impl TokenFromOAuth1Arg {
699    pub fn new(oauth1_token: String, oauth1_token_secret: String) -> Self {
700        TokenFromOAuth1Arg {
701            oauth1_token,
702            oauth1_token_secret,
703        }
704    }
705}
706
707const TOKEN_FROM_O_AUTH1_ARG_FIELDS: &[&str] = &["oauth1_token",
708                                                 "oauth1_token_secret"];
709impl TokenFromOAuth1Arg {
710    pub(crate) fn internal_deserialize<'de, V: ::serde::de::MapAccess<'de>>(
711        map: V,
712    ) -> Result<TokenFromOAuth1Arg, V::Error> {
713        Self::internal_deserialize_opt(map, false).map(Option::unwrap)
714    }
715
716    pub(crate) fn internal_deserialize_opt<'de, V: ::serde::de::MapAccess<'de>>(
717        mut map: V,
718        optional: bool,
719    ) -> Result<Option<TokenFromOAuth1Arg>, V::Error> {
720        let mut field_oauth1_token = None;
721        let mut field_oauth1_token_secret = None;
722        let mut nothing = true;
723        while let Some(key) = map.next_key::<&str>()? {
724            nothing = false;
725            match key {
726                "oauth1_token" => {
727                    if field_oauth1_token.is_some() {
728                        return Err(::serde::de::Error::duplicate_field("oauth1_token"));
729                    }
730                    field_oauth1_token = Some(map.next_value()?);
731                }
732                "oauth1_token_secret" => {
733                    if field_oauth1_token_secret.is_some() {
734                        return Err(::serde::de::Error::duplicate_field("oauth1_token_secret"));
735                    }
736                    field_oauth1_token_secret = Some(map.next_value()?);
737                }
738                _ => {
739                    // unknown field allowed and ignored
740                    map.next_value::<::serde_json::Value>()?;
741                }
742            }
743        }
744        if optional && nothing {
745            return Ok(None);
746        }
747        let result = TokenFromOAuth1Arg {
748            oauth1_token: field_oauth1_token.ok_or_else(|| ::serde::de::Error::missing_field("oauth1_token"))?,
749            oauth1_token_secret: field_oauth1_token_secret.ok_or_else(|| ::serde::de::Error::missing_field("oauth1_token_secret"))?,
750        };
751        Ok(Some(result))
752    }
753
754    pub(crate) fn internal_serialize<S: ::serde::ser::Serializer>(
755        &self,
756        s: &mut S::SerializeStruct,
757    ) -> Result<(), S::Error> {
758        use serde::ser::SerializeStruct;
759        s.serialize_field("oauth1_token", &self.oauth1_token)?;
760        s.serialize_field("oauth1_token_secret", &self.oauth1_token_secret)?;
761        Ok(())
762    }
763}
764
765impl<'de> ::serde::de::Deserialize<'de> for TokenFromOAuth1Arg {
766    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
767        // struct deserializer
768        use serde::de::{MapAccess, Visitor};
769        struct StructVisitor;
770        impl<'de> Visitor<'de> for StructVisitor {
771            type Value = TokenFromOAuth1Arg;
772            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
773                f.write_str("a TokenFromOAuth1Arg struct")
774            }
775            fn visit_map<V: MapAccess<'de>>(self, map: V) -> Result<Self::Value, V::Error> {
776                TokenFromOAuth1Arg::internal_deserialize(map)
777            }
778        }
779        deserializer.deserialize_struct("TokenFromOAuth1Arg", TOKEN_FROM_O_AUTH1_ARG_FIELDS, StructVisitor)
780    }
781}
782
783impl ::serde::ser::Serialize for TokenFromOAuth1Arg {
784    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
785        // struct serializer
786        use serde::ser::SerializeStruct;
787        let mut s = serializer.serialize_struct("TokenFromOAuth1Arg", 2)?;
788        self.internal_serialize::<S>(&mut s)?;
789        s.end()
790    }
791}
792
793#[derive(Debug, Clone, PartialEq, Eq)]
794#[non_exhaustive] // variants may be added in the future
795pub enum TokenFromOAuth1Error {
796    /// Part or all of the OAuth 1.0 access token info is invalid.
797    InvalidOauth1TokenInfo,
798    /// The authorized app does not match the app associated with the supplied access token.
799    AppIdMismatch,
800    /// Catch-all used for unrecognized values returned from the server. Encountering this value
801    /// typically indicates that this SDK version is out of date.
802    Other,
803}
804
805impl<'de> ::serde::de::Deserialize<'de> for TokenFromOAuth1Error {
806    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
807        // union deserializer
808        use serde::de::{self, MapAccess, Visitor};
809        struct EnumVisitor;
810        impl<'de> Visitor<'de> for EnumVisitor {
811            type Value = TokenFromOAuth1Error;
812            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
813                f.write_str("a TokenFromOAuth1Error structure")
814            }
815            fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> Result<Self::Value, V::Error> {
816                let tag: &str = match map.next_key()? {
817                    Some(".tag") => map.next_value()?,
818                    _ => return Err(de::Error::missing_field(".tag"))
819                };
820                let value = match tag {
821                    "invalid_oauth1_token_info" => TokenFromOAuth1Error::InvalidOauth1TokenInfo,
822                    "app_id_mismatch" => TokenFromOAuth1Error::AppIdMismatch,
823                    _ => TokenFromOAuth1Error::Other,
824                };
825                crate::eat_json_fields(&mut map)?;
826                Ok(value)
827            }
828        }
829        const VARIANTS: &[&str] = &["invalid_oauth1_token_info",
830                                    "app_id_mismatch",
831                                    "other"];
832        deserializer.deserialize_struct("TokenFromOAuth1Error", VARIANTS, EnumVisitor)
833    }
834}
835
836impl ::serde::ser::Serialize for TokenFromOAuth1Error {
837    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
838        // union serializer
839        use serde::ser::SerializeStruct;
840        match self {
841            TokenFromOAuth1Error::InvalidOauth1TokenInfo => {
842                // unit
843                let mut s = serializer.serialize_struct("TokenFromOAuth1Error", 1)?;
844                s.serialize_field(".tag", "invalid_oauth1_token_info")?;
845                s.end()
846            }
847            TokenFromOAuth1Error::AppIdMismatch => {
848                // unit
849                let mut s = serializer.serialize_struct("TokenFromOAuth1Error", 1)?;
850                s.serialize_field(".tag", "app_id_mismatch")?;
851                s.end()
852            }
853            TokenFromOAuth1Error::Other => Err(::serde::ser::Error::custom("cannot serialize 'Other' variant"))
854        }
855    }
856}
857
858impl ::std::error::Error for TokenFromOAuth1Error {
859}
860
861impl ::std::fmt::Display for TokenFromOAuth1Error {
862    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
863        match self {
864            TokenFromOAuth1Error::InvalidOauth1TokenInfo => f.write_str("Part or all of the OAuth 1.0 access token info is invalid."),
865            TokenFromOAuth1Error::AppIdMismatch => f.write_str("The authorized app does not match the app associated with the supplied access token."),
866            _ => write!(f, "{:?}", *self),
867        }
868    }
869}
870
871#[derive(Debug, Clone, PartialEq, Eq)]
872#[non_exhaustive] // structs may have more fields added in the future.
873pub struct TokenFromOAuth1Result {
874    /// The OAuth 2.0 token generated from the supplied OAuth 1.0 token.
875    pub oauth2_token: String,
876}
877
878impl TokenFromOAuth1Result {
879    pub fn new(oauth2_token: String) -> Self {
880        TokenFromOAuth1Result {
881            oauth2_token,
882        }
883    }
884}
885
886const TOKEN_FROM_O_AUTH1_RESULT_FIELDS: &[&str] = &["oauth2_token"];
887impl TokenFromOAuth1Result {
888    pub(crate) fn internal_deserialize<'de, V: ::serde::de::MapAccess<'de>>(
889        map: V,
890    ) -> Result<TokenFromOAuth1Result, V::Error> {
891        Self::internal_deserialize_opt(map, false).map(Option::unwrap)
892    }
893
894    pub(crate) fn internal_deserialize_opt<'de, V: ::serde::de::MapAccess<'de>>(
895        mut map: V,
896        optional: bool,
897    ) -> Result<Option<TokenFromOAuth1Result>, V::Error> {
898        let mut field_oauth2_token = None;
899        let mut nothing = true;
900        while let Some(key) = map.next_key::<&str>()? {
901            nothing = false;
902            match key {
903                "oauth2_token" => {
904                    if field_oauth2_token.is_some() {
905                        return Err(::serde::de::Error::duplicate_field("oauth2_token"));
906                    }
907                    field_oauth2_token = Some(map.next_value()?);
908                }
909                _ => {
910                    // unknown field allowed and ignored
911                    map.next_value::<::serde_json::Value>()?;
912                }
913            }
914        }
915        if optional && nothing {
916            return Ok(None);
917        }
918        let result = TokenFromOAuth1Result {
919            oauth2_token: field_oauth2_token.ok_or_else(|| ::serde::de::Error::missing_field("oauth2_token"))?,
920        };
921        Ok(Some(result))
922    }
923
924    pub(crate) fn internal_serialize<S: ::serde::ser::Serializer>(
925        &self,
926        s: &mut S::SerializeStruct,
927    ) -> Result<(), S::Error> {
928        use serde::ser::SerializeStruct;
929        s.serialize_field("oauth2_token", &self.oauth2_token)?;
930        Ok(())
931    }
932}
933
934impl<'de> ::serde::de::Deserialize<'de> for TokenFromOAuth1Result {
935    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
936        // struct deserializer
937        use serde::de::{MapAccess, Visitor};
938        struct StructVisitor;
939        impl<'de> Visitor<'de> for StructVisitor {
940            type Value = TokenFromOAuth1Result;
941            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
942                f.write_str("a TokenFromOAuth1Result struct")
943            }
944            fn visit_map<V: MapAccess<'de>>(self, map: V) -> Result<Self::Value, V::Error> {
945                TokenFromOAuth1Result::internal_deserialize(map)
946            }
947        }
948        deserializer.deserialize_struct("TokenFromOAuth1Result", TOKEN_FROM_O_AUTH1_RESULT_FIELDS, StructVisitor)
949    }
950}
951
952impl ::serde::ser::Serialize for TokenFromOAuth1Result {
953    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
954        // struct serializer
955        use serde::ser::SerializeStruct;
956        let mut s = serializer.serialize_struct("TokenFromOAuth1Result", 1)?;
957        self.internal_serialize::<S>(&mut s)?;
958        s.end()
959    }
960}
961
962#[derive(Debug, Clone, PartialEq, Eq)]
963#[non_exhaustive] // structs may have more fields added in the future.
964pub struct TokenScopeError {
965    /// The required scope to access the route.
966    pub required_scope: String,
967}
968
969impl TokenScopeError {
970    pub fn new(required_scope: String) -> Self {
971        TokenScopeError {
972            required_scope,
973        }
974    }
975}
976
977const TOKEN_SCOPE_ERROR_FIELDS: &[&str] = &["required_scope"];
978impl TokenScopeError {
979    pub(crate) fn internal_deserialize<'de, V: ::serde::de::MapAccess<'de>>(
980        map: V,
981    ) -> Result<TokenScopeError, V::Error> {
982        Self::internal_deserialize_opt(map, false).map(Option::unwrap)
983    }
984
985    pub(crate) fn internal_deserialize_opt<'de, V: ::serde::de::MapAccess<'de>>(
986        mut map: V,
987        optional: bool,
988    ) -> Result<Option<TokenScopeError>, V::Error> {
989        let mut field_required_scope = None;
990        let mut nothing = true;
991        while let Some(key) = map.next_key::<&str>()? {
992            nothing = false;
993            match key {
994                "required_scope" => {
995                    if field_required_scope.is_some() {
996                        return Err(::serde::de::Error::duplicate_field("required_scope"));
997                    }
998                    field_required_scope = Some(map.next_value()?);
999                }
1000                _ => {
1001                    // unknown field allowed and ignored
1002                    map.next_value::<::serde_json::Value>()?;
1003                }
1004            }
1005        }
1006        if optional && nothing {
1007            return Ok(None);
1008        }
1009        let result = TokenScopeError {
1010            required_scope: field_required_scope.ok_or_else(|| ::serde::de::Error::missing_field("required_scope"))?,
1011        };
1012        Ok(Some(result))
1013    }
1014
1015    pub(crate) fn internal_serialize<S: ::serde::ser::Serializer>(
1016        &self,
1017        s: &mut S::SerializeStruct,
1018    ) -> Result<(), S::Error> {
1019        use serde::ser::SerializeStruct;
1020        s.serialize_field("required_scope", &self.required_scope)?;
1021        Ok(())
1022    }
1023}
1024
1025impl<'de> ::serde::de::Deserialize<'de> for TokenScopeError {
1026    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
1027        // struct deserializer
1028        use serde::de::{MapAccess, Visitor};
1029        struct StructVisitor;
1030        impl<'de> Visitor<'de> for StructVisitor {
1031            type Value = TokenScopeError;
1032            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
1033                f.write_str("a TokenScopeError struct")
1034            }
1035            fn visit_map<V: MapAccess<'de>>(self, map: V) -> Result<Self::Value, V::Error> {
1036                TokenScopeError::internal_deserialize(map)
1037            }
1038        }
1039        deserializer.deserialize_struct("TokenScopeError", TOKEN_SCOPE_ERROR_FIELDS, StructVisitor)
1040    }
1041}
1042
1043impl ::serde::ser::Serialize for TokenScopeError {
1044    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
1045        // struct serializer
1046        use serde::ser::SerializeStruct;
1047        let mut s = serializer.serialize_struct("TokenScopeError", 1)?;
1048        self.internal_serialize::<S>(&mut s)?;
1049        s.end()
1050    }
1051}
1052
1053#[derive(Debug, Clone, PartialEq, Eq)]
1054#[non_exhaustive] // structs may have more fields added in the future.
1055pub struct UnauthorizedAccountIdUsageError {
1056    /// The account IDs that the caller does not have permission to use.
1057    pub unauthorized_account_ids: Vec<String>,
1058}
1059
1060impl UnauthorizedAccountIdUsageError {
1061    pub fn new(unauthorized_account_ids: Vec<String>) -> Self {
1062        UnauthorizedAccountIdUsageError {
1063            unauthorized_account_ids,
1064        }
1065    }
1066}
1067
1068const UNAUTHORIZED_ACCOUNT_ID_USAGE_ERROR_FIELDS: &[&str] = &["unauthorized_account_ids"];
1069impl UnauthorizedAccountIdUsageError {
1070    pub(crate) fn internal_deserialize<'de, V: ::serde::de::MapAccess<'de>>(
1071        map: V,
1072    ) -> Result<UnauthorizedAccountIdUsageError, V::Error> {
1073        Self::internal_deserialize_opt(map, false).map(Option::unwrap)
1074    }
1075
1076    pub(crate) fn internal_deserialize_opt<'de, V: ::serde::de::MapAccess<'de>>(
1077        mut map: V,
1078        optional: bool,
1079    ) -> Result<Option<UnauthorizedAccountIdUsageError>, V::Error> {
1080        let mut field_unauthorized_account_ids = None;
1081        let mut nothing = true;
1082        while let Some(key) = map.next_key::<&str>()? {
1083            nothing = false;
1084            match key {
1085                "unauthorized_account_ids" => {
1086                    if field_unauthorized_account_ids.is_some() {
1087                        return Err(::serde::de::Error::duplicate_field("unauthorized_account_ids"));
1088                    }
1089                    field_unauthorized_account_ids = Some(map.next_value()?);
1090                }
1091                _ => {
1092                    // unknown field allowed and ignored
1093                    map.next_value::<::serde_json::Value>()?;
1094                }
1095            }
1096        }
1097        if optional && nothing {
1098            return Ok(None);
1099        }
1100        let result = UnauthorizedAccountIdUsageError {
1101            unauthorized_account_ids: field_unauthorized_account_ids.ok_or_else(|| ::serde::de::Error::missing_field("unauthorized_account_ids"))?,
1102        };
1103        Ok(Some(result))
1104    }
1105
1106    pub(crate) fn internal_serialize<S: ::serde::ser::Serializer>(
1107        &self,
1108        s: &mut S::SerializeStruct,
1109    ) -> Result<(), S::Error> {
1110        use serde::ser::SerializeStruct;
1111        s.serialize_field("unauthorized_account_ids", &self.unauthorized_account_ids)?;
1112        Ok(())
1113    }
1114}
1115
1116impl<'de> ::serde::de::Deserialize<'de> for UnauthorizedAccountIdUsageError {
1117    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
1118        // struct deserializer
1119        use serde::de::{MapAccess, Visitor};
1120        struct StructVisitor;
1121        impl<'de> Visitor<'de> for StructVisitor {
1122            type Value = UnauthorizedAccountIdUsageError;
1123            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
1124                f.write_str("a UnauthorizedAccountIdUsageError struct")
1125            }
1126            fn visit_map<V: MapAccess<'de>>(self, map: V) -> Result<Self::Value, V::Error> {
1127                UnauthorizedAccountIdUsageError::internal_deserialize(map)
1128            }
1129        }
1130        deserializer.deserialize_struct("UnauthorizedAccountIdUsageError", UNAUTHORIZED_ACCOUNT_ID_USAGE_ERROR_FIELDS, StructVisitor)
1131    }
1132}
1133
1134impl ::serde::ser::Serialize for UnauthorizedAccountIdUsageError {
1135    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
1136        // struct serializer
1137        use serde::ser::SerializeStruct;
1138        let mut s = serializer.serialize_struct("UnauthorizedAccountIdUsageError", 1)?;
1139        self.internal_serialize::<S>(&mut s)?;
1140        s.end()
1141    }
1142}
1143