Skip to content

Commit e27b837

Browse files
committed
Add Debug and Clone to all publis API structs, and some CS
1 parent 4eaa5a7 commit e27b837

File tree

13 files changed

+149
-119
lines changed

13 files changed

+149
-119
lines changed

examples/settings.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@ async fn main() {
3939
.expect("Could not join the remote server.");
4040

4141
// We check if the task failed.
42-
if task.is_failure() {
43-
panic!(
44-
"Could not update the settings. {}",
45-
task.unwrap_failure().error_message
46-
);
47-
}
42+
assert!(
43+
!task.is_failure(),
44+
"Could not update the settings. {}",
45+
task.unwrap_failure().error_message
46+
);
4847

4948
// And finally we delete the `Index`.
5049
my_index
@@ -56,10 +55,9 @@ async fn main() {
5655
.expect("Could not join the remote server.");
5756

5857
// We check if the task failed.
59-
if task.is_failure() {
60-
panic!(
61-
"Could not delete the index. {}",
62-
task.unwrap_failure().error_message
63-
);
64-
}
58+
assert!(
59+
!task.is_failure(),
60+
"Could not delete the index. {}",
61+
task.unwrap_failure().error_message
62+
);
6563
}

src/client.rs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ impl Client {
4646
pub fn new(host: impl Into<String>, api_key: Option<impl Into<String>>) -> Client {
4747
Client {
4848
host: host.into(),
49-
api_key: api_key.map(|key| key.into()),
49+
api_key: api_key.map(std::convert::Into::into),
5050
}
5151
}
5252

53-
fn parse_indexes_results_from_value(&self, value: Value) -> Result<IndexesResults, Error> {
53+
fn parse_indexes_results_from_value(&self, value: &Value) -> Result<IndexesResults, Error> {
5454
let raw_indexes = value["results"].as_array().unwrap();
5555

5656
let indexes_results = IndexesResults {
@@ -121,6 +121,7 @@ impl Client {
121121
/// # movies.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
122122
/// # });
123123
/// ```
124+
#[must_use]
124125
pub fn multi_search(&self) -> MultiSearchQuery {
125126
MultiSearchQuery::new(self)
126127
}
@@ -136,6 +137,7 @@ impl Client {
136137
///
137138
/// assert_eq!(client.get_host(), "http://doggo.dog");
138139
/// ```
140+
#[must_use]
139141
pub fn get_host(&self) -> &str {
140142
&self.host
141143
}
@@ -151,6 +153,7 @@ impl Client {
151153
///
152154
/// assert_eq!(client.get_api_key(), Some("doggo"));
153155
/// ```
156+
#[must_use]
154157
pub fn get_api_key(&self) -> Option<&str> {
155158
self.api_key.as_deref()
156159
}
@@ -174,7 +177,7 @@ impl Client {
174177
/// ```
175178
pub async fn list_all_indexes(&self) -> Result<IndexesResults, Error> {
176179
let value = self.list_all_indexes_raw().await?;
177-
let indexes_results = self.parse_indexes_results_from_value(value)?;
180+
let indexes_results = self.parse_indexes_results_from_value(&value)?;
178181
Ok(indexes_results)
179182
}
180183

@@ -203,7 +206,7 @@ impl Client {
203206
indexes_query: &IndexesQuery<'_>,
204207
) -> Result<IndexesResults, Error> {
205208
let value = self.list_all_indexes_raw_with(indexes_query).await?;
206-
let indexes_results = self.parse_indexes_results_from_value(value)?;
209+
let indexes_results = self.parse_indexes_results_from_value(&value)?;
207210

208211
Ok(indexes_results)
209212
}
@@ -301,7 +304,7 @@ impl Client {
301304

302305
/// Get a raw JSON [Index], this index should already exist.
303306
///
304-
/// If you use it directly from an [Index], you can use the method [Index::fetch_info], which is the equivalent method from an index.
307+
/// If you use it directly from an [Index], you can use the method [`Index::fetch_info`], which is the equivalent method from an index.
305308
///
306309
/// # Example
307310
///
@@ -385,7 +388,7 @@ impl Client {
385388

386389
/// Delete an index from its UID.
387390
///
388-
/// To delete an [Index], use the [Index::delete] method.
391+
/// To delete an [Index], use the [`Index::delete`] method.
389392
pub async fn delete_index(&self, uid: impl AsRef<str>) -> Result<TaskInfo, Error> {
390393
request::<(), (), TaskInfo>(
391394
&format!("{}/indexes/{}", self.host, uid.as_ref()),
@@ -396,25 +399,25 @@ impl Client {
396399
.await
397400
}
398401

399-
/// Alias for [Client::list_all_indexes].
402+
/// Alias for [`Client::list_all_indexes`].
400403
pub async fn get_indexes(&self) -> Result<IndexesResults, Error> {
401404
self.list_all_indexes().await
402405
}
403406

404-
/// Alias for [Client::list_all_indexes_with].
407+
/// Alias for [`Client::list_all_indexes_with`].
405408
pub async fn get_indexes_with(
406409
&self,
407410
indexes_query: &IndexesQuery<'_>,
408411
) -> Result<IndexesResults, Error> {
409412
self.list_all_indexes_with(indexes_query).await
410413
}
411414

412-
/// Alias for [Client::list_all_indexes_raw].
415+
/// Alias for [`Client::list_all_indexes_raw`].
413416
pub async fn get_indexes_raw(&self) -> Result<Value, Error> {
414417
self.list_all_indexes_raw().await
415418
}
416419

417-
/// Alias for [Client::list_all_indexes_raw_with].
420+
/// Alias for [`Client::list_all_indexes_raw_with`].
418421
pub async fn get_indexes_raw_with(
419422
&self,
420423
indexes_query: &IndexesQuery<'_>,
@@ -549,7 +552,7 @@ impl Client {
549552

550553
/// Get the API [Keys](Key) from Meilisearch with parameters.
551554
///
552-
/// See [Client::create_key], [Client::get_key], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#get-all-keys).
555+
/// See [`Client::create_key`], [`Client::get_key`], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#get-all-keys).
553556
///
554557
/// # Example
555558
///
@@ -583,7 +586,7 @@ impl Client {
583586

584587
/// Get the API [Keys](Key) from Meilisearch.
585588
///
586-
/// See [Client::create_key], [Client::get_key], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#get-all-keys).
589+
/// See [`Client::create_key`], [`Client::get_key`], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#get-all-keys).
587590
///
588591
/// # Example
589592
///
@@ -614,7 +617,7 @@ impl Client {
614617

615618
/// Get one API [Key] from Meilisearch.
616619
///
617-
/// See also [Client::create_key], [Client::get_keys], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#get-one-key).
620+
/// See also [`Client::create_key`], [`Client::get_keys`], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#get-one-key).
618621
///
619622
/// # Example
620623
///
@@ -646,7 +649,7 @@ impl Client {
646649

647650
/// Delete an API [Key] from Meilisearch.
648651
///
649-
/// See also [Client::create_key], [Client::update_key], [Client::get_key], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#delete-a-key).
652+
/// See also [`Client::create_key`], [`Client::update_key`], [`Client::get_key`], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#delete-a-key).
650653
///
651654
/// # Example
652655
///
@@ -681,7 +684,7 @@ impl Client {
681684

682685
/// Create an API [Key] in Meilisearch.
683686
///
684-
/// See also [Client::update_key], [Client::delete_key], [Client::get_key], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#create-a-key).
687+
/// See also [`Client::update_key`], [`Client::delete_key`], [`Client::get_key`], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#create-a-key).
685688
///
686689
/// # Example
687690
///
@@ -718,7 +721,7 @@ impl Client {
718721

719722
/// Update an API [Key] in Meilisearch.
720723
///
721-
/// See also [Client::create_key], [Client::delete_key], [Client::get_key], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#update-a-key).
724+
/// See also [`Client::create_key`], [`Client::delete_key`], [`Client::get_key`], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#update-a-key).
722725
///
723726
/// # Example
724727
///
@@ -787,9 +790,9 @@ impl Client {
787790
///
788791
/// `timeout` = The maximum time to wait for processing to complete. **Default = 5000ms**
789792
///
790-
/// If the waited time exceeds `timeout` then an [Error::Timeout] will be returned.
793+
/// If the waited time exceeds `timeout` then an [`Error::Timeout`] will be returned.
791794
///
792-
/// See also [Index::wait_for_task, Task::wait_for_completion, TaskInfo::wait_for_completion].
795+
/// See also [`Index::wait_for_task`, `Task::wait_for_completion`, `TaskInfo::wait_for_completion`].
793796
///
794797
/// # Example
795798
///
@@ -917,7 +920,7 @@ impl Client {
917920
Ok(tasks)
918921
}
919922

920-
/// Cancel tasks with filters [TasksCancelQuery].
923+
/// Cancel tasks with filters [`TasksCancelQuery`].
921924
///
922925
/// # Example
923926
///
@@ -953,7 +956,7 @@ impl Client {
953956
Ok(tasks)
954957
}
955958

956-
/// Delete tasks with filters [TasksDeleteQuery].
959+
/// Delete tasks with filters [`TasksDeleteQuery`].
957960
///
958961
/// # Example
959962
///
@@ -1054,7 +1057,7 @@ impl Client {
10541057
}
10551058
}
10561059

1057-
#[derive(Deserialize)]
1060+
#[derive(Debug, Clone, Deserialize)]
10581061
#[serde(rename_all = "camelCase")]
10591062
pub struct ClientStats {
10601063
pub database_size: usize,
@@ -1073,7 +1076,7 @@ pub struct ClientStats {
10731076
/// status: "available".to_string(),
10741077
/// };
10751078
/// ```
1076-
#[derive(Deserialize)]
1079+
#[derive(Debug, Clone, Deserialize)]
10771080
pub struct Health {
10781081
pub status: String,
10791082
}
@@ -1090,7 +1093,7 @@ pub struct Health {
10901093
/// pkg_version: "0.1.1".to_string(),
10911094
/// };
10921095
/// ```
1093-
#[derive(Deserialize)]
1096+
#[derive(Debug, Clone, Deserialize)]
10941097
#[serde(rename_all = "camelCase")]
10951098
pub struct Version {
10961099
pub commit_sha: String,
@@ -1331,7 +1334,7 @@ mod tests {
13311334
let mut key = KeyBuilder::new();
13321335
key.with_action(Action::DocumentsAdd)
13331336
.with_name(&name)
1334-
.with_expires_at(expires_at.clone())
1337+
.with_expires_at(expires_at)
13351338
.with_description("a description")
13361339
.with_index("*");
13371340
let key = client.create_key(key).await.unwrap();

src/documents.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ use crate::{errors::Error, indexes::Index};
5656
pub trait IndexConfig {
5757
const INDEX_STR: &'static str;
5858

59+
#[must_use]
5960
fn index(client: &Client) -> Index {
6061
client.index(Self::INDEX_STR)
6162
}
@@ -82,6 +83,7 @@ pub struct DocumentQuery<'a> {
8283
}
8384

8485
impl<'a> DocumentQuery<'a> {
86+
#[must_use]
8587
pub fn new(index: &Index) -> DocumentQuery {
8688
DocumentQuery {
8789
index,
@@ -188,6 +190,7 @@ pub struct DocumentsQuery<'a> {
188190
}
189191

190192
impl<'a> DocumentsQuery<'a> {
193+
#[must_use]
191194
pub fn new(index: &Index) -> DocumentsQuery {
192195
DocumentsQuery {
193196
index,

src/dumps.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl Client {
8787
}
8888
}
8989

90-
/// Alias for [create_dump](Client::create_dump).
90+
/// Alias for [`create_dump`](Client::create_dump).
9191
pub async fn create_dump(client: &Client) -> Result<TaskInfo, Error> {
9292
client.create_dump().await
9393
}

0 commit comments

Comments
 (0)