Skip to content

Commit fc1d41d

Browse files
Merge #466
466: Add Debug and Clone to all public API structs, and some CS r=bidoubiwa a=omid # Pull Request ## What does this PR do? - Add Debug and Clone to all public API structs - some code style Co-authored-by: Omid Rad <[email protected]> Co-authored-by: Omid Rad <[email protected]>
2 parents 55ee372 + 8565e64 commit fc1d41d

File tree

13 files changed

+106
-109
lines changed

13 files changed

+106
-109
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
}

examples/web_app/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl Component for Model {
4444
type Message = Msg;
4545
type Properties = ();
4646
fn create(_ctx: &Context<Self>) -> Model {
47-
Self {
47+
Model {
4848
// The index method avoids checking the existence of the index.
4949
// It won't make any HTTP request so the function is not async so it's easier to use.
5050
// Use only if you are sure that the index exists.

src/client.rs

Lines changed: 24 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 {
@@ -174,7 +174,7 @@ impl Client {
174174
/// ```
175175
pub async fn list_all_indexes(&self) -> Result<IndexesResults, Error> {
176176
let value = self.list_all_indexes_raw().await?;
177-
let indexes_results = self.parse_indexes_results_from_value(value)?;
177+
let indexes_results = self.parse_indexes_results_from_value(&value)?;
178178
Ok(indexes_results)
179179
}
180180

@@ -203,7 +203,7 @@ impl Client {
203203
indexes_query: &IndexesQuery<'_>,
204204
) -> Result<IndexesResults, Error> {
205205
let value = self.list_all_indexes_raw_with(indexes_query).await?;
206-
let indexes_results = self.parse_indexes_results_from_value(value)?;
206+
let indexes_results = self.parse_indexes_results_from_value(&value)?;
207207

208208
Ok(indexes_results)
209209
}
@@ -301,7 +301,7 @@ impl Client {
301301

302302
/// Get a raw JSON [Index], this index should already exist.
303303
///
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.
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.
305305
///
306306
/// # Example
307307
///
@@ -385,7 +385,7 @@ impl Client {
385385

386386
/// Delete an index from its UID.
387387
///
388-
/// To delete an [Index], use the [Index::delete] method.
388+
/// To delete an [Index], use the [`Index::delete`] method.
389389
pub async fn delete_index(&self, uid: impl AsRef<str>) -> Result<TaskInfo, Error> {
390390
request::<(), (), TaskInfo>(
391391
&format!("{}/indexes/{}", self.host, uid.as_ref()),
@@ -396,25 +396,25 @@ impl Client {
396396
.await
397397
}
398398

399-
/// Alias for [Client::list_all_indexes].
399+
/// Alias for [`Client::list_all_indexes`].
400400
pub async fn get_indexes(&self) -> Result<IndexesResults, Error> {
401401
self.list_all_indexes().await
402402
}
403403

404-
/// Alias for [Client::list_all_indexes_with].
404+
/// Alias for [`Client::list_all_indexes_with`].
405405
pub async fn get_indexes_with(
406406
&self,
407407
indexes_query: &IndexesQuery<'_>,
408408
) -> Result<IndexesResults, Error> {
409409
self.list_all_indexes_with(indexes_query).await
410410
}
411411

412-
/// Alias for [Client::list_all_indexes_raw].
412+
/// Alias for [`Client::list_all_indexes_raw`].
413413
pub async fn get_indexes_raw(&self) -> Result<Value, Error> {
414414
self.list_all_indexes_raw().await
415415
}
416416

417-
/// Alias for [Client::list_all_indexes_raw_with].
417+
/// Alias for [`Client::list_all_indexes_raw_with`].
418418
pub async fn get_indexes_raw_with(
419419
&self,
420420
indexes_query: &IndexesQuery<'_>,
@@ -549,7 +549,7 @@ impl Client {
549549

550550
/// Get the API [Keys](Key) from Meilisearch with parameters.
551551
///
552-
/// See [Client::create_key], [Client::get_key], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#get-all-keys).
552+
/// See [`Client::create_key`], [`Client::get_key`], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#get-all-keys).
553553
///
554554
/// # Example
555555
///
@@ -583,7 +583,7 @@ impl Client {
583583

584584
/// Get the API [Keys](Key) from Meilisearch.
585585
///
586-
/// See [Client::create_key], [Client::get_key], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#get-all-keys).
586+
/// See [`Client::create_key`], [`Client::get_key`], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#get-all-keys).
587587
///
588588
/// # Example
589589
///
@@ -614,7 +614,7 @@ impl Client {
614614

615615
/// Get one API [Key] from Meilisearch.
616616
///
617-
/// See also [Client::create_key], [Client::get_keys], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#get-one-key).
617+
/// See also [`Client::create_key`], [`Client::get_keys`], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#get-one-key).
618618
///
619619
/// # Example
620620
///
@@ -646,7 +646,7 @@ impl Client {
646646

647647
/// Delete an API [Key] from Meilisearch.
648648
///
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).
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).
650650
///
651651
/// # Example
652652
///
@@ -681,7 +681,7 @@ impl Client {
681681

682682
/// Create an API [Key] in Meilisearch.
683683
///
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).
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).
685685
///
686686
/// # Example
687687
///
@@ -718,7 +718,7 @@ impl Client {
718718

719719
/// Update an API [Key] in Meilisearch.
720720
///
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).
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).
722722
///
723723
/// # Example
724724
///
@@ -787,9 +787,9 @@ impl Client {
787787
///
788788
/// `timeout` = The maximum time to wait for processing to complete. **Default = 5000ms**
789789
///
790-
/// If the waited time exceeds `timeout` then an [Error::Timeout] will be returned.
790+
/// If the waited time exceeds `timeout` then an [`Error::Timeout`] will be returned.
791791
///
792-
/// See also [Index::wait_for_task, Task::wait_for_completion, TaskInfo::wait_for_completion].
792+
/// See also [`Index::wait_for_task`, `Task::wait_for_completion`, `TaskInfo::wait_for_completion`].
793793
///
794794
/// # Example
795795
///
@@ -917,7 +917,7 @@ impl Client {
917917
Ok(tasks)
918918
}
919919

920-
/// Cancel tasks with filters [TasksCancelQuery].
920+
/// Cancel tasks with filters [`TasksCancelQuery`].
921921
///
922922
/// # Example
923923
///
@@ -953,7 +953,7 @@ impl Client {
953953
Ok(tasks)
954954
}
955955

956-
/// Delete tasks with filters [TasksDeleteQuery].
956+
/// Delete tasks with filters [`TasksDeleteQuery`].
957957
///
958958
/// # Example
959959
///
@@ -1054,7 +1054,7 @@ impl Client {
10541054
}
10551055
}
10561056

1057-
#[derive(Deserialize)]
1057+
#[derive(Debug, Clone, Deserialize)]
10581058
#[serde(rename_all = "camelCase")]
10591059
pub struct ClientStats {
10601060
pub database_size: usize,
@@ -1073,7 +1073,7 @@ pub struct ClientStats {
10731073
/// status: "available".to_string(),
10741074
/// };
10751075
/// ```
1076-
#[derive(Deserialize)]
1076+
#[derive(Debug, Clone, Deserialize)]
10771077
pub struct Health {
10781078
pub status: String,
10791079
}
@@ -1090,7 +1090,7 @@ pub struct Health {
10901090
/// pkg_version: "0.1.1".to_string(),
10911091
/// };
10921092
/// ```
1093-
#[derive(Deserialize)]
1093+
#[derive(Debug, Clone, Deserialize)]
10941094
#[serde(rename_all = "camelCase")]
10951095
pub struct Version {
10961096
pub commit_sha: String,
@@ -1331,7 +1331,7 @@ mod tests {
13311331
let mut key = KeyBuilder::new();
13321332
key.with_action(Action::DocumentsAdd)
13331333
.with_name(&name)
1334-
.with_expires_at(expires_at.clone())
1334+
.with_expires_at(expires_at)
13351335
.with_description("a description")
13361336
.with_index("*");
13371337
let key = client.create_key(key).await.unwrap();

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)