Skip to content

Commit dbfac54

Browse files
committed
fix: Clippy warnings
1 parent 5152998 commit dbfac54

File tree

7 files changed

+220
-16
lines changed

7 files changed

+220
-16
lines changed

couch_rs/src/client.rs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use crate::{
55
types::system::{CouchResponse, CouchStatus, DbInfo},
66
};
77
use base64::engine::general_purpose;
8-
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
8+
use percent_encoding::{NON_ALPHANUMERIC, utf8_percent_encode};
99
use reqwest::{
10-
header::{self, HeaderMap, HeaderValue, CONTENT_TYPE, REFERER, USER_AGENT},
1110
Method, RequestBuilder, StatusCode, Url,
11+
header::{self, CONTENT_TYPE, HeaderMap, HeaderValue, REFERER, USER_AGENT},
1212
};
1313
use std::{collections::HashMap, io::Write, time::Duration};
1414

@@ -50,6 +50,7 @@ pub(crate) async fn is_ok(request: RequestBuilder) -> bool {
5050
/// Client handles the URI manipulation logic and the HTTP calls to the `CouchDB` REST API.
5151
/// It is also responsible for the creation/access/destruction of databases.
5252
#[derive(Debug, Clone)]
53+
#[allow(clippy::struct_field_names)]
5354
pub struct Client {
5455
client: reqwest::Client,
5556
_gzip: bool,
@@ -67,13 +68,19 @@ impl Client {
6768
/// new creates a new Couch client with a default timeout of 10 seconds.
6869
/// The timeout is applied from when the request starts connecting until the response body has finished.
6970
/// The URI has to be in this format: <http://hostname:5984>, for example: <http://192.168.64.5:5984>
71+
///
72+
/// # Errors
73+
/// Returns a `CouchError` if the URI is invalid.
7074
pub fn new(uri: &str, username: &str, password: &str) -> CouchResult<Client> {
7175
Client::new_with_timeout(uri, Some(username), Some(password), Some(DEFAULT_TIME_OUT))
7276
}
7377

7478
/// `new_no_auth` creates a new Couch client with a default timeout of 10 seconds. *Without authentication*.
7579
/// The timeout is applied from when the request starts connecting until the response body has finished.
7680
/// The URI has to be in this format: <http://hostname:5984>, for example: <http://192.168.64.5:5984>
81+
///
82+
/// # Errors
83+
/// Returns a `CouchError` if the URI is invalid.
7784
pub fn new_no_auth(uri: &str) -> CouchResult<Client> {
7885
Client::new_with_timeout(uri, None, None, Some(DEFAULT_TIME_OUT))
7986
}
@@ -82,6 +89,9 @@ impl Client {
8289
/// The timeout is applied from when the request starts connecting until the response body has finished.
8390
/// The URI that will be used is: <http://hostname:5984>, with a username of "admin" and a password
8491
/// of "password". Use this only for testing!!!
92+
///
93+
/// # Errors
94+
/// Returns a `CouchError` if the URI is invalid.
8595
pub fn new_local_test() -> CouchResult<Client> {
8696
Client::new_with_timeout(
8797
TEST_DB_HOST,
@@ -97,6 +107,9 @@ impl Client {
97107
///
98108
/// # Panics
99109
/// Panics when the AUTHORIZATION header can not be set on the request.
110+
///
111+
/// # Errors
112+
/// Returns a `CouchError` if the URI is invalid.
100113
pub fn new_with_timeout(
101114
uri: &str,
102115
username: Option<&str>,
@@ -139,6 +152,10 @@ impl Client {
139152
self
140153
}
141154

155+
/// Set the URI of the client
156+
///
157+
/// # Errors
158+
/// Returns a `CouchError` if the URI is invalid.
142159
pub fn set_uri(&mut self, uri: &str) -> CouchResult<&Self> {
143160
self.uri = parse_server(uri)?;
144161
Ok(self)
@@ -169,6 +186,9 @@ impl Client {
169186
/// Ok(())
170187
/// }
171188
///```
189+
///
190+
/// # Errors
191+
/// Returns a `CouchError` if the request fails.
172192
pub async fn list_dbs(&self) -> CouchResult<Vec<String>> {
173193
let response = self.get("/_all_dbs", None).send().await?;
174194
let data = response.json().await?;
@@ -183,6 +203,9 @@ impl Client {
183203
}
184204

185205
/// Connect to an existing database, or create a new one, when this one does not exist.
206+
///
207+
/// # Errors
208+
/// Returns a `CouchError` if the request fails.
186209
pub async fn db(&self, dbname: &str) -> CouchResult<Database> {
187210
let name = self.build_dbname(dbname);
188211

@@ -201,6 +224,9 @@ impl Client {
201224
}
202225

203226
/// Create a new database with the given name
227+
///
228+
/// # Errors
229+
/// Returns a `CouchError` if the request fails.
204230
pub async fn make_db(&self, dbname: &str) -> CouchResult<Database> {
205231
let name = self.build_dbname(dbname);
206232

@@ -224,6 +250,9 @@ impl Client {
224250
}
225251

226252
/// Destroy the database with the given name
253+
///
254+
/// # Errors
255+
/// Returns a `CouchError` if the request fails.
227256
pub async fn destroy_db(&self, dbname: &str) -> CouchResult<bool> {
228257
let response = self
229258
.delete(&self.build_dbname(dbname), None)
@@ -257,13 +286,19 @@ impl Client {
257286
/// return Ok(());
258287
/// }
259288
/// ```
289+
///
290+
/// # Errors
291+
/// Returns a `CouchError` if the request fails.
260292
pub async fn exists(&self, dbname: &str) -> CouchResult<bool> {
261293
let result = self.head(&self.build_dbname(dbname), None).send().await?;
262294
Ok(result.status().is_success())
263295
}
264296

265297
/// Gets information about the specified database.
266298
/// See [common](https://docs.couchdb.org/en/stable/api/database/common.html) for more details.
299+
///
300+
/// # Errors
301+
/// Returns a `CouchError` if the request fails.
267302
pub async fn get_info(&self, dbname: &str) -> CouchResult<DbInfo> {
268303
let response = self
269304
.get(&self.build_dbname(dbname), None)
@@ -277,6 +312,9 @@ impl Client {
277312
/// Returns meta information about the instance. The response contains information about the server,
278313
/// including a welcome message and the version of the server.
279314
/// See [common](https://docs.couchdb.org/en/stable/api/server/common.html) for more details.
315+
///
316+
/// # Errors
317+
/// Returns a `CouchError` if the request fails.
280318
pub async fn check_status(&self) -> CouchResult<CouchStatus> {
281319
let response = self.get("", None).headers(construct_json_headers(None)).send().await?;
282320

@@ -286,6 +324,9 @@ impl Client {
286324

287325
/// Returns membership information about the cluster.
288326
/// See [_membership](https://docs.couchdb.org/en/latest/api/server/common.html?#membership) for more details.
327+
///
328+
/// # Errors
329+
/// Returns a `CouchError` if the request fails.
289330
pub async fn membership(&self) -> CouchResult<Membership> {
290331
let response = self.get("/_membership", None).send().await?;
291332
let membership = response.json().await?;
@@ -294,6 +335,9 @@ impl Client {
294335

295336
/// Returns `cluster_setup` information about the cluster.
296337
/// See [_cluster_setup](https://docs.couchdb.org/en/latest/api/server/common.html?#cluster-setup) for more details.
338+
///
339+
/// # Errors
340+
/// Returns a `CouchError` if the request fails.
297341
pub async fn cluster_setup(&self, request: EnsureDbsExist) -> CouchResult<ClusterSetup> {
298342
let ensure_dbs_array = serde_json::to_value(&request.ensure_dbs_exist)?;
299343
let ensure_dbs_arrays = serde_json::to_string(&ensure_dbs_array)?;

0 commit comments

Comments
 (0)