1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#![deny(
missing_docs,
rust_2018_idioms,
)]
#![cfg_attr(docsrs, feature(external_doc))]
#![cfg_attr(docsrs, doc(include = "../README.md"))]
#![cfg_attr(not(docsrs), doc = "Dropbox SDK for Rust. See README.md for more details.")]
#![cfg_attr(docsrs, feature(doc_cfg))]
macro_rules! if_feature {
($feature_name:expr, $($item:item)*) => {
$(
#[cfg(feature = $feature_name)]
#[cfg_attr(docsrs, doc(cfg(feature = $feature_name)))]
$item
)*
}
}
#[macro_use] extern crate log;
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("error from HTTP client: {0}")]
HttpClient(Box<dyn std::error::Error + Send + Sync + 'static>),
#[error("JSON serialization error: {0}")]
Json(#[from] serde_json::Error),
#[error("Dropbox API returned something unexpected: {0}")]
UnexpectedResponse(&'static str),
#[error("Dropbox API indicated that the request was malformed: {0}")]
BadRequest(String),
#[error("Dropbox API indicated that the access token is bad: {0}")]
InvalidToken(String),
#[error("Dropbox API declined the request due to rate-limiting ({reason}), \
retry after {retry_after_seconds}s")]
RateLimited {
reason: String,
retry_after_seconds: u32,
},
#[error("Dropbox API had an internal server error: {0}")]
ServerError(String),
#[error("Dropbox API returned HTTP {code} {status} - {json}")]
UnexpectedHttpError {
code: u16,
status: String,
json: String,
},
}
pub type Result<T> = std::result::Result<T, Error>;
if_feature! { "default_client", pub mod default_client; }
pub mod client_trait;
pub use client_trait::{AppAuthClient, NoauthClient, UserAuthClient, TeamAuthClient};
pub(crate) mod client_helpers;
pub mod oauth2;
mod generated;
pub use generated::*;
#[derive(Copy)]
pub enum NoError {}
impl Clone for NoError {
fn clone(&self) -> NoError {
unreachable(*self)
}
}
impl std::cmp::PartialEq<NoError> for NoError {
fn eq(&self, _: &NoError) -> bool {
unreachable(*self)
}
}
impl std::error::Error for NoError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
unreachable(*self)
}
fn description(&self) -> &str {
unreachable(*self)
}
fn cause(&self) -> Option<&dyn std::error::Error> {
unreachable(*self)
}
}
impl std::fmt::Debug for NoError {
fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
unreachable(*self)
}
}
impl std::fmt::Display for NoError {
fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
unreachable(*self)
}
}
impl<'de> serde::de::Deserialize<'de> for NoError {
fn deserialize<D: serde::de::Deserializer<'de>>(_: D)
-> std::result::Result<Self, D::Error>
{
Err(serde::de::Error::custom(
"method has no defined error type, but an error was returned"))
}
}
#[inline(always)]
fn unreachable(x: NoError) -> ! {
match x {}
}