1#![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
12pub type Date = String ;
13pub type DisplayName = String;
14pub type DisplayNameLegacy = String;
15pub type DropboxTimestamp = String ;
16pub type EmailAddress = String;
17pub type LanguageCode = String;
18pub type NamePart = String;
19pub type NamespaceId = String;
20pub type OptionalNamePart = String;
21pub type SessionId = String;
22pub type SharedFolderId = NamespaceId;
23
24#[derive(Debug, Clone, PartialEq, Eq)]
25#[non_exhaustive] pub struct DropboxDuration {
27 pub seconds: i64,
28 pub nanos: i32,
29}
30
31impl DropboxDuration {
32 pub fn new(seconds: i64, nanos: i32) -> Self {
33 DropboxDuration {
34 seconds,
35 nanos,
36 }
37 }
38}
39
40const DROPBOX_DURATION_FIELDS: &[&str] = &["seconds",
41 "nanos"];
42impl DropboxDuration {
43 pub(crate) fn internal_deserialize<'de, V: ::serde::de::MapAccess<'de>>(
44 map: V,
45 ) -> Result<DropboxDuration, V::Error> {
46 Self::internal_deserialize_opt(map, false).map(Option::unwrap)
47 }
48
49 pub(crate) fn internal_deserialize_opt<'de, V: ::serde::de::MapAccess<'de>>(
50 mut map: V,
51 optional: bool,
52 ) -> Result<Option<DropboxDuration>, V::Error> {
53 let mut field_seconds = None;
54 let mut field_nanos = None;
55 let mut nothing = true;
56 while let Some(key) = map.next_key::<&str>()? {
57 nothing = false;
58 match key {
59 "seconds" => {
60 if field_seconds.is_some() {
61 return Err(::serde::de::Error::duplicate_field("seconds"));
62 }
63 field_seconds = Some(map.next_value()?);
64 }
65 "nanos" => {
66 if field_nanos.is_some() {
67 return Err(::serde::de::Error::duplicate_field("nanos"));
68 }
69 field_nanos = Some(map.next_value()?);
70 }
71 _ => {
72 map.next_value::<::serde_json::Value>()?;
74 }
75 }
76 }
77 if optional && nothing {
78 return Ok(None);
79 }
80 let result = DropboxDuration {
81 seconds: field_seconds.ok_or_else(|| ::serde::de::Error::missing_field("seconds"))?,
82 nanos: field_nanos.ok_or_else(|| ::serde::de::Error::missing_field("nanos"))?,
83 };
84 Ok(Some(result))
85 }
86
87 pub(crate) fn internal_serialize<S: ::serde::ser::Serializer>(
88 &self,
89 s: &mut S::SerializeStruct,
90 ) -> Result<(), S::Error> {
91 use serde::ser::SerializeStruct;
92 s.serialize_field("seconds", &self.seconds)?;
93 s.serialize_field("nanos", &self.nanos)?;
94 Ok(())
95 }
96}
97
98impl<'de> ::serde::de::Deserialize<'de> for DropboxDuration {
99 fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
100 use serde::de::{MapAccess, Visitor};
102 struct StructVisitor;
103 impl<'de> Visitor<'de> for StructVisitor {
104 type Value = DropboxDuration;
105 fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
106 f.write_str("a DropboxDuration struct")
107 }
108 fn visit_map<V: MapAccess<'de>>(self, map: V) -> Result<Self::Value, V::Error> {
109 DropboxDuration::internal_deserialize(map)
110 }
111 }
112 deserializer.deserialize_struct("DropboxDuration", DROPBOX_DURATION_FIELDS, StructVisitor)
113 }
114}
115
116impl ::serde::ser::Serialize for DropboxDuration {
117 fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
118 use serde::ser::SerializeStruct;
120 let mut s = serializer.serialize_struct("DropboxDuration", 2)?;
121 self.internal_serialize::<S>(&mut s)?;
122 s.end()
123 }
124}
125
126#[derive(Debug, Clone, PartialEq, Eq)]
127#[non_exhaustive] pub enum PathRoot {
129 Home,
132 Root(NamespaceId),
135 NamespaceId(NamespaceId),
138 Other,
141}
142
143impl<'de> ::serde::de::Deserialize<'de> for PathRoot {
144 fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
145 use serde::de::{self, MapAccess, Visitor};
147 struct EnumVisitor;
148 impl<'de> Visitor<'de> for EnumVisitor {
149 type Value = PathRoot;
150 fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
151 f.write_str("a PathRoot structure")
152 }
153 fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> Result<Self::Value, V::Error> {
154 let tag: &str = match map.next_key()? {
155 Some(".tag") => map.next_value()?,
156 _ => return Err(de::Error::missing_field(".tag"))
157 };
158 let value = match tag {
159 "home" => PathRoot::Home,
160 "root" => {
161 match map.next_key()? {
162 Some("root") => PathRoot::Root(map.next_value()?),
163 None => return Err(de::Error::missing_field("root")),
164 _ => return Err(de::Error::unknown_field(tag, VARIANTS))
165 }
166 }
167 "namespace_id" => {
168 match map.next_key()? {
169 Some("namespace_id") => PathRoot::NamespaceId(map.next_value()?),
170 None => return Err(de::Error::missing_field("namespace_id")),
171 _ => return Err(de::Error::unknown_field(tag, VARIANTS))
172 }
173 }
174 _ => PathRoot::Other,
175 };
176 crate::eat_json_fields(&mut map)?;
177 Ok(value)
178 }
179 }
180 const VARIANTS: &[&str] = &["home",
181 "root",
182 "namespace_id",
183 "other"];
184 deserializer.deserialize_struct("PathRoot", VARIANTS, EnumVisitor)
185 }
186}
187
188impl ::serde::ser::Serialize for PathRoot {
189 fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
190 use serde::ser::SerializeStruct;
192 match self {
193 PathRoot::Home => {
194 let mut s = serializer.serialize_struct("PathRoot", 1)?;
196 s.serialize_field(".tag", "home")?;
197 s.end()
198 }
199 PathRoot::Root(x) => {
200 let mut s = serializer.serialize_struct("PathRoot", 2)?;
202 s.serialize_field(".tag", "root")?;
203 s.serialize_field("root", x)?;
204 s.end()
205 }
206 PathRoot::NamespaceId(x) => {
207 let mut s = serializer.serialize_struct("PathRoot", 2)?;
209 s.serialize_field(".tag", "namespace_id")?;
210 s.serialize_field("namespace_id", x)?;
211 s.end()
212 }
213 PathRoot::Other => Err(::serde::ser::Error::custom("cannot serialize 'Other' variant"))
214 }
215 }
216}
217
218#[derive(Debug, Clone, PartialEq, Eq)]
219#[non_exhaustive] pub enum PathRootError {
221 InvalidRoot(RootInfo),
224 NoPermission,
226 Other,
229}
230
231impl<'de> ::serde::de::Deserialize<'de> for PathRootError {
232 fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
233 use serde::de::{self, MapAccess, Visitor};
235 struct EnumVisitor;
236 impl<'de> Visitor<'de> for EnumVisitor {
237 type Value = PathRootError;
238 fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
239 f.write_str("a PathRootError structure")
240 }
241 fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> Result<Self::Value, V::Error> {
242 let tag: &str = match map.next_key()? {
243 Some(".tag") => map.next_value()?,
244 _ => return Err(de::Error::missing_field(".tag"))
245 };
246 let value = match tag {
247 "invalid_root" => {
248 match map.next_key()? {
249 Some("invalid_root") => PathRootError::InvalidRoot(map.next_value()?),
250 None => return Err(de::Error::missing_field("invalid_root")),
251 _ => return Err(de::Error::unknown_field(tag, VARIANTS))
252 }
253 }
254 "no_permission" => PathRootError::NoPermission,
255 _ => PathRootError::Other,
256 };
257 crate::eat_json_fields(&mut map)?;
258 Ok(value)
259 }
260 }
261 const VARIANTS: &[&str] = &["invalid_root",
262 "no_permission",
263 "other"];
264 deserializer.deserialize_struct("PathRootError", VARIANTS, EnumVisitor)
265 }
266}
267
268impl ::serde::ser::Serialize for PathRootError {
269 fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
270 use serde::ser::SerializeStruct;
272 match self {
273 PathRootError::InvalidRoot(x) => {
274 let mut s = serializer.serialize_struct("PathRootError", 2)?;
276 s.serialize_field(".tag", "invalid_root")?;
277 s.serialize_field("invalid_root", x)?;
278 s.end()
279 }
280 PathRootError::NoPermission => {
281 let mut s = serializer.serialize_struct("PathRootError", 1)?;
283 s.serialize_field(".tag", "no_permission")?;
284 s.end()
285 }
286 PathRootError::Other => Err(::serde::ser::Error::custom("cannot serialize 'Other' variant"))
287 }
288 }
289}
290
291impl ::std::error::Error for PathRootError {
292}
293
294impl ::std::fmt::Display for PathRootError {
295 fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
296 match self {
297 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),
298 PathRootError::NoPermission => f.write_str("You don't have permission to access the namespace id in Dropbox-API-Path-Root header."),
299 _ => write!(f, "{:?}", *self),
300 }
301 }
302}
303
304#[derive(Debug, Clone, PartialEq, Eq)]
306#[non_exhaustive] pub enum RootInfo {
308 Team(TeamRootInfo),
309 User(UserRootInfo),
310 Other,
313}
314
315impl<'de> ::serde::de::Deserialize<'de> for RootInfo {
316 fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
317 use serde::de::{self, MapAccess, Visitor};
319 struct EnumVisitor;
320 impl<'de> Visitor<'de> for EnumVisitor {
321 type Value = RootInfo;
322 fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
323 f.write_str("a RootInfo structure")
324 }
325 fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> Result<Self::Value, V::Error> {
326 let tag = match map.next_key()? {
327 Some(".tag") => map.next_value()?,
328 _ => return Err(de::Error::missing_field(".tag"))
329 };
330 match tag {
331 "team" => Ok(RootInfo::Team(TeamRootInfo::internal_deserialize(map)?)),
332 "user" => Ok(RootInfo::User(UserRootInfo::internal_deserialize(map)?)),
333 _ => {
334 crate::eat_json_fields(&mut map)?;
335 Ok(RootInfo::Other)
336 }
337 }
338 }
339 }
340 const VARIANTS: &[&str] = &["team",
341 "user"];
342 deserializer.deserialize_struct("RootInfo", VARIANTS, EnumVisitor)
343 }
344}
345
346impl ::serde::ser::Serialize for RootInfo {
347 fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
348 use serde::ser::SerializeStruct;
350 match self {
351 RootInfo::Team(x) => {
352 let mut s = serializer.serialize_struct("RootInfo", 4)?;
353 s.serialize_field(".tag", "team")?;
354 x.internal_serialize::<S>(&mut s)?;
355 s.end()
356 }
357 RootInfo::User(x) => {
358 let mut s = serializer.serialize_struct("RootInfo", 4)?;
359 s.serialize_field(".tag", "user")?;
360 x.internal_serialize::<S>(&mut s)?;
361 s.end()
362 }
363 RootInfo::Other => Err(::serde::ser::Error::custom("cannot serialize unknown variant"))
364 }
365 }
366}
367
368#[derive(Debug, Clone, PartialEq, Eq)]
370#[non_exhaustive] pub struct TeamRootInfo {
372 pub root_namespace_id: NamespaceId,
377 pub home_namespace_id: NamespaceId,
379 pub home_path: String,
381}
382
383impl TeamRootInfo {
384 pub fn new(
385 root_namespace_id: NamespaceId,
386 home_namespace_id: NamespaceId,
387 home_path: String,
388 ) -> Self {
389 TeamRootInfo {
390 root_namespace_id,
391 home_namespace_id,
392 home_path,
393 }
394 }
395}
396
397const TEAM_ROOT_INFO_FIELDS: &[&str] = &["root_namespace_id",
398 "home_namespace_id",
399 "home_path"];
400impl TeamRootInfo {
401 pub(crate) fn internal_deserialize<'de, V: ::serde::de::MapAccess<'de>>(
402 map: V,
403 ) -> Result<TeamRootInfo, V::Error> {
404 Self::internal_deserialize_opt(map, false).map(Option::unwrap)
405 }
406
407 pub(crate) fn internal_deserialize_opt<'de, V: ::serde::de::MapAccess<'de>>(
408 mut map: V,
409 optional: bool,
410 ) -> Result<Option<TeamRootInfo>, V::Error> {
411 let mut field_root_namespace_id = None;
412 let mut field_home_namespace_id = None;
413 let mut field_home_path = None;
414 let mut nothing = true;
415 while let Some(key) = map.next_key::<&str>()? {
416 nothing = false;
417 match key {
418 "root_namespace_id" => {
419 if field_root_namespace_id.is_some() {
420 return Err(::serde::de::Error::duplicate_field("root_namespace_id"));
421 }
422 field_root_namespace_id = Some(map.next_value()?);
423 }
424 "home_namespace_id" => {
425 if field_home_namespace_id.is_some() {
426 return Err(::serde::de::Error::duplicate_field("home_namespace_id"));
427 }
428 field_home_namespace_id = Some(map.next_value()?);
429 }
430 "home_path" => {
431 if field_home_path.is_some() {
432 return Err(::serde::de::Error::duplicate_field("home_path"));
433 }
434 field_home_path = Some(map.next_value()?);
435 }
436 _ => {
437 map.next_value::<::serde_json::Value>()?;
439 }
440 }
441 }
442 if optional && nothing {
443 return Ok(None);
444 }
445 let result = TeamRootInfo {
446 root_namespace_id: field_root_namespace_id.ok_or_else(|| ::serde::de::Error::missing_field("root_namespace_id"))?,
447 home_namespace_id: field_home_namespace_id.ok_or_else(|| ::serde::de::Error::missing_field("home_namespace_id"))?,
448 home_path: field_home_path.ok_or_else(|| ::serde::de::Error::missing_field("home_path"))?,
449 };
450 Ok(Some(result))
451 }
452
453 pub(crate) fn internal_serialize<S: ::serde::ser::Serializer>(
454 &self,
455 s: &mut S::SerializeStruct,
456 ) -> Result<(), S::Error> {
457 use serde::ser::SerializeStruct;
458 s.serialize_field("root_namespace_id", &self.root_namespace_id)?;
459 s.serialize_field("home_namespace_id", &self.home_namespace_id)?;
460 s.serialize_field("home_path", &self.home_path)?;
461 Ok(())
462 }
463}
464
465impl<'de> ::serde::de::Deserialize<'de> for TeamRootInfo {
466 fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
467 use serde::de::{MapAccess, Visitor};
469 struct StructVisitor;
470 impl<'de> Visitor<'de> for StructVisitor {
471 type Value = TeamRootInfo;
472 fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
473 f.write_str("a TeamRootInfo struct")
474 }
475 fn visit_map<V: MapAccess<'de>>(self, map: V) -> Result<Self::Value, V::Error> {
476 TeamRootInfo::internal_deserialize(map)
477 }
478 }
479 deserializer.deserialize_struct("TeamRootInfo", TEAM_ROOT_INFO_FIELDS, StructVisitor)
480 }
481}
482
483impl ::serde::ser::Serialize for TeamRootInfo {
484 fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
485 use serde::ser::SerializeStruct;
487 let mut s = serializer.serialize_struct("TeamRootInfo", 3)?;
488 self.internal_serialize::<S>(&mut s)?;
489 s.end()
490 }
491}
492
493impl From<TeamRootInfo> for RootInfo {
495 fn from(subtype: TeamRootInfo) -> Self {
496 RootInfo::Team(subtype)
497 }
498}
499#[derive(Debug, Clone, PartialEq, Eq)]
502#[non_exhaustive] pub struct UserRootInfo {
504 pub root_namespace_id: NamespaceId,
509 pub home_namespace_id: NamespaceId,
511 pub home_path: Option<String>,
513}
514
515impl UserRootInfo {
516 pub fn new(root_namespace_id: NamespaceId, home_namespace_id: NamespaceId) -> Self {
517 UserRootInfo {
518 root_namespace_id,
519 home_namespace_id,
520 home_path: None,
521 }
522 }
523
524 pub fn with_home_path(mut self, value: String) -> Self {
525 self.home_path = Some(value);
526 self
527 }
528}
529
530const USER_ROOT_INFO_FIELDS: &[&str] = &["root_namespace_id",
531 "home_namespace_id",
532 "home_path"];
533impl UserRootInfo {
534 pub(crate) fn internal_deserialize<'de, V: ::serde::de::MapAccess<'de>>(
535 map: V,
536 ) -> Result<UserRootInfo, V::Error> {
537 Self::internal_deserialize_opt(map, false).map(Option::unwrap)
538 }
539
540 pub(crate) fn internal_deserialize_opt<'de, V: ::serde::de::MapAccess<'de>>(
541 mut map: V,
542 optional: bool,
543 ) -> Result<Option<UserRootInfo>, V::Error> {
544 let mut field_root_namespace_id = None;
545 let mut field_home_namespace_id = None;
546 let mut field_home_path = None;
547 let mut nothing = true;
548 while let Some(key) = map.next_key::<&str>()? {
549 nothing = false;
550 match key {
551 "root_namespace_id" => {
552 if field_root_namespace_id.is_some() {
553 return Err(::serde::de::Error::duplicate_field("root_namespace_id"));
554 }
555 field_root_namespace_id = Some(map.next_value()?);
556 }
557 "home_namespace_id" => {
558 if field_home_namespace_id.is_some() {
559 return Err(::serde::de::Error::duplicate_field("home_namespace_id"));
560 }
561 field_home_namespace_id = Some(map.next_value()?);
562 }
563 "home_path" => {
564 if field_home_path.is_some() {
565 return Err(::serde::de::Error::duplicate_field("home_path"));
566 }
567 field_home_path = Some(map.next_value()?);
568 }
569 _ => {
570 map.next_value::<::serde_json::Value>()?;
572 }
573 }
574 }
575 if optional && nothing {
576 return Ok(None);
577 }
578 let result = UserRootInfo {
579 root_namespace_id: field_root_namespace_id.ok_or_else(|| ::serde::de::Error::missing_field("root_namespace_id"))?,
580 home_namespace_id: field_home_namespace_id.ok_or_else(|| ::serde::de::Error::missing_field("home_namespace_id"))?,
581 home_path: field_home_path.and_then(Option::flatten),
582 };
583 Ok(Some(result))
584 }
585
586 pub(crate) fn internal_serialize<S: ::serde::ser::Serializer>(
587 &self,
588 s: &mut S::SerializeStruct,
589 ) -> Result<(), S::Error> {
590 use serde::ser::SerializeStruct;
591 s.serialize_field("root_namespace_id", &self.root_namespace_id)?;
592 s.serialize_field("home_namespace_id", &self.home_namespace_id)?;
593 if let Some(val) = &self.home_path {
594 s.serialize_field("home_path", val)?;
595 }
596 Ok(())
597 }
598}
599
600impl<'de> ::serde::de::Deserialize<'de> for UserRootInfo {
601 fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
602 use serde::de::{MapAccess, Visitor};
604 struct StructVisitor;
605 impl<'de> Visitor<'de> for StructVisitor {
606 type Value = UserRootInfo;
607 fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
608 f.write_str("a UserRootInfo struct")
609 }
610 fn visit_map<V: MapAccess<'de>>(self, map: V) -> Result<Self::Value, V::Error> {
611 UserRootInfo::internal_deserialize(map)
612 }
613 }
614 deserializer.deserialize_struct("UserRootInfo", USER_ROOT_INFO_FIELDS, StructVisitor)
615 }
616}
617
618impl ::serde::ser::Serialize for UserRootInfo {
619 fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
620 use serde::ser::SerializeStruct;
622 let mut s = serializer.serialize_struct("UserRootInfo", 3)?;
623 self.internal_serialize::<S>(&mut s)?;
624 s.end()
625 }
626}
627
628impl From<UserRootInfo> for RootInfo {
630 fn from(subtype: UserRootInfo) -> Self {
631 RootInfo::User(subtype)
632 }
633}