From e27b83767b1bb6eebc01ccbefc0be9685c648c18 Mon Sep 17 00:00:00 2001 From: Omid Rad Date: Tue, 9 May 2023 17:00:45 +0200 Subject: [PATCH 1/5] Add Debug and Clone to all publis API structs, and some CS --- examples/settings.rs | 22 +++++++--------- src/client.rs | 51 ++++++++++++++++++----------------- src/documents.rs | 3 +++ src/dumps.rs | 2 +- src/indexes.rs | 38 +++++++++++++------------- src/key.rs | 14 +++++----- src/lib.rs | 12 ++++----- src/request.rs | 14 +++++----- src/search.rs | 14 ++++++---- src/settings.rs | 63 +++++++++++++++++++++++++------------------- src/task_info.rs | 7 ++--- src/tasks.rs | 22 +++++++++++----- src/tenant_tokens.rs | 6 ++--- 13 files changed, 149 insertions(+), 119 deletions(-) diff --git a/examples/settings.rs b/examples/settings.rs index 64952697..11f6d0f1 100644 --- a/examples/settings.rs +++ b/examples/settings.rs @@ -39,12 +39,11 @@ async fn main() { .expect("Could not join the remote server."); // We check if the task failed. - if task.is_failure() { - panic!( - "Could not update the settings. {}", - task.unwrap_failure().error_message - ); - } + assert!( + !task.is_failure(), + "Could not update the settings. {}", + task.unwrap_failure().error_message + ); // And finally we delete the `Index`. my_index @@ -56,10 +55,9 @@ async fn main() { .expect("Could not join the remote server."); // We check if the task failed. - if task.is_failure() { - panic!( - "Could not delete the index. {}", - task.unwrap_failure().error_message - ); - } + assert!( + !task.is_failure(), + "Could not delete the index. {}", + task.unwrap_failure().error_message + ); } diff --git a/src/client.rs b/src/client.rs index 8231ba0c..57e2655d 100644 --- a/src/client.rs +++ b/src/client.rs @@ -46,11 +46,11 @@ impl Client { pub fn new(host: impl Into, api_key: Option>) -> Client { Client { host: host.into(), - api_key: api_key.map(|key| key.into()), + api_key: api_key.map(std::convert::Into::into), } } - fn parse_indexes_results_from_value(&self, value: Value) -> Result { + fn parse_indexes_results_from_value(&self, value: &Value) -> Result { let raw_indexes = value["results"].as_array().unwrap(); let indexes_results = IndexesResults { @@ -121,6 +121,7 @@ impl Client { /// # movies.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` + #[must_use] pub fn multi_search(&self) -> MultiSearchQuery { MultiSearchQuery::new(self) } @@ -136,6 +137,7 @@ impl Client { /// /// assert_eq!(client.get_host(), "http://doggo.dog"); /// ``` + #[must_use] pub fn get_host(&self) -> &str { &self.host } @@ -151,6 +153,7 @@ impl Client { /// /// assert_eq!(client.get_api_key(), Some("doggo")); /// ``` + #[must_use] pub fn get_api_key(&self) -> Option<&str> { self.api_key.as_deref() } @@ -174,7 +177,7 @@ impl Client { /// ``` pub async fn list_all_indexes(&self) -> Result { let value = self.list_all_indexes_raw().await?; - let indexes_results = self.parse_indexes_results_from_value(value)?; + let indexes_results = self.parse_indexes_results_from_value(&value)?; Ok(indexes_results) } @@ -203,7 +206,7 @@ impl Client { indexes_query: &IndexesQuery<'_>, ) -> Result { let value = self.list_all_indexes_raw_with(indexes_query).await?; - let indexes_results = self.parse_indexes_results_from_value(value)?; + let indexes_results = self.parse_indexes_results_from_value(&value)?; Ok(indexes_results) } @@ -301,7 +304,7 @@ impl Client { /// Get a raw JSON [Index], this index should already exist. /// - /// If you use it directly from an [Index], you can use the method [Index::fetch_info], which is the equivalent method from an index. + /// If you use it directly from an [Index], you can use the method [`Index::fetch_info`], which is the equivalent method from an index. /// /// # Example /// @@ -385,7 +388,7 @@ impl Client { /// Delete an index from its UID. /// - /// To delete an [Index], use the [Index::delete] method. + /// To delete an [Index], use the [`Index::delete`] method. pub async fn delete_index(&self, uid: impl AsRef) -> Result { request::<(), (), TaskInfo>( &format!("{}/indexes/{}", self.host, uid.as_ref()), @@ -396,12 +399,12 @@ impl Client { .await } - /// Alias for [Client::list_all_indexes]. + /// Alias for [`Client::list_all_indexes`]. pub async fn get_indexes(&self) -> Result { self.list_all_indexes().await } - /// Alias for [Client::list_all_indexes_with]. + /// Alias for [`Client::list_all_indexes_with`]. pub async fn get_indexes_with( &self, indexes_query: &IndexesQuery<'_>, @@ -409,12 +412,12 @@ impl Client { self.list_all_indexes_with(indexes_query).await } - /// Alias for [Client::list_all_indexes_raw]. + /// Alias for [`Client::list_all_indexes_raw`]. pub async fn get_indexes_raw(&self) -> Result { self.list_all_indexes_raw().await } - /// Alias for [Client::list_all_indexes_raw_with]. + /// Alias for [`Client::list_all_indexes_raw_with`]. pub async fn get_indexes_raw_with( &self, indexes_query: &IndexesQuery<'_>, @@ -549,7 +552,7 @@ impl Client { /// Get the API [Keys](Key) from Meilisearch with parameters. /// - /// See [Client::create_key], [Client::get_key], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#get-all-keys). + /// See [`Client::create_key`], [`Client::get_key`], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#get-all-keys). /// /// # Example /// @@ -583,7 +586,7 @@ impl Client { /// Get the API [Keys](Key) from Meilisearch. /// - /// See [Client::create_key], [Client::get_key], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#get-all-keys). + /// See [`Client::create_key`], [`Client::get_key`], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#get-all-keys). /// /// # Example /// @@ -614,7 +617,7 @@ impl Client { /// Get one API [Key] from Meilisearch. /// - /// See also [Client::create_key], [Client::get_keys], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#get-one-key). + /// See also [`Client::create_key`], [`Client::get_keys`], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#get-one-key). /// /// # Example /// @@ -646,7 +649,7 @@ impl Client { /// Delete an API [Key] from Meilisearch. /// - /// 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). + /// 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). /// /// # Example /// @@ -681,7 +684,7 @@ impl Client { /// Create an API [Key] in Meilisearch. /// - /// 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). + /// 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). /// /// # Example /// @@ -718,7 +721,7 @@ impl Client { /// Update an API [Key] in Meilisearch. /// - /// 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). + /// 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). /// /// # Example /// @@ -787,9 +790,9 @@ impl Client { /// /// `timeout` = The maximum time to wait for processing to complete. **Default = 5000ms** /// - /// If the waited time exceeds `timeout` then an [Error::Timeout] will be returned. + /// If the waited time exceeds `timeout` then an [`Error::Timeout`] will be returned. /// - /// See also [Index::wait_for_task, Task::wait_for_completion, TaskInfo::wait_for_completion]. + /// See also [`Index::wait_for_task`, `Task::wait_for_completion`, `TaskInfo::wait_for_completion`]. /// /// # Example /// @@ -917,7 +920,7 @@ impl Client { Ok(tasks) } - /// Cancel tasks with filters [TasksCancelQuery]. + /// Cancel tasks with filters [`TasksCancelQuery`]. /// /// # Example /// @@ -953,7 +956,7 @@ impl Client { Ok(tasks) } - /// Delete tasks with filters [TasksDeleteQuery]. + /// Delete tasks with filters [`TasksDeleteQuery`]. /// /// # Example /// @@ -1054,7 +1057,7 @@ impl Client { } } -#[derive(Deserialize)] +#[derive(Debug, Clone, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ClientStats { pub database_size: usize, @@ -1073,7 +1076,7 @@ pub struct ClientStats { /// status: "available".to_string(), /// }; /// ``` -#[derive(Deserialize)] +#[derive(Debug, Clone, Deserialize)] pub struct Health { pub status: String, } @@ -1090,7 +1093,7 @@ pub struct Health { /// pkg_version: "0.1.1".to_string(), /// }; /// ``` -#[derive(Deserialize)] +#[derive(Debug, Clone, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Version { pub commit_sha: String, @@ -1331,7 +1334,7 @@ mod tests { let mut key = KeyBuilder::new(); key.with_action(Action::DocumentsAdd) .with_name(&name) - .with_expires_at(expires_at.clone()) + .with_expires_at(expires_at) .with_description("a description") .with_index("*"); let key = client.create_key(key).await.unwrap(); diff --git a/src/documents.rs b/src/documents.rs index 79c31856..ec7e6a1c 100644 --- a/src/documents.rs +++ b/src/documents.rs @@ -56,6 +56,7 @@ use crate::{errors::Error, indexes::Index}; pub trait IndexConfig { const INDEX_STR: &'static str; + #[must_use] fn index(client: &Client) -> Index { client.index(Self::INDEX_STR) } @@ -82,6 +83,7 @@ pub struct DocumentQuery<'a> { } impl<'a> DocumentQuery<'a> { + #[must_use] pub fn new(index: &Index) -> DocumentQuery { DocumentQuery { index, @@ -188,6 +190,7 @@ pub struct DocumentsQuery<'a> { } impl<'a> DocumentsQuery<'a> { + #[must_use] pub fn new(index: &Index) -> DocumentsQuery { DocumentsQuery { index, diff --git a/src/dumps.rs b/src/dumps.rs index 03274f84..d9791376 100644 --- a/src/dumps.rs +++ b/src/dumps.rs @@ -87,7 +87,7 @@ impl Client { } } -/// Alias for [create_dump](Client::create_dump). +/// Alias for [`create_dump`](Client::create_dump). pub async fn create_dump(client: &Client) -> Result { client.create_dump().await } diff --git a/src/indexes.rs b/src/indexes.rs index c80023f2..4b870f01 100644 --- a/src/indexes.rs +++ b/src/indexes.rs @@ -16,7 +16,7 @@ use time::OffsetDateTime; /// # Example /// /// You can create an index remotly and, if that succeed, make an `Index` out of it. -/// See the [Client::create_index] method. +/// See the [`Client::create_index`] method. /// ``` /// # use meilisearch_sdk::{client::*, indexes::*}; /// # @@ -189,7 +189,7 @@ impl Index { /// Search for documents matching a specific query in the index. /// - /// See also [Index::search]. + /// See also [`Index::search`]. /// /// # Example /// @@ -234,7 +234,7 @@ impl Index { /// Search for documents matching a specific query in the index. /// - /// See also [Index::execute_query]. + /// See also [`Index::execute_query`]. /// /// # Example /// @@ -268,6 +268,7 @@ impl Index { /// # movies.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` + #[must_use] pub fn search(&self) -> SearchQuery { SearchQuery::new(self) } @@ -483,9 +484,9 @@ impl Index { /// If you send an already existing document (same id) the **whole existing document** will be overwritten by the new document. /// Fields previously in the document not present in the new document are removed. /// - /// For a partial update of the document see [Index::add_or_update]. + /// For a partial update of the document see [`Index::add_or_update`]. /// - /// You can use the alias [Index::add_documents] if you prefer. + /// You can use the alias [`Index::add_documents`] if you prefer. /// /// # Example /// @@ -563,7 +564,7 @@ impl Index { /// If you send an already existing document (same id) the **whole existing document** will be overwritten by the new document. /// Fields previously in the document not present in the new document are removed. /// - /// For a partial update of the document see [Index::add_or_update_unchecked_payload]. + /// For a partial update of the document see [`Index::add_or_update_unchecked_payload`]. /// /// # Example /// @@ -623,7 +624,7 @@ impl Index { .await } - /// Alias for [Index::add_or_replace]. + /// Alias for [`Index::add_or_replace`]. pub async fn add_documents( &self, documents: &[T], @@ -637,7 +638,7 @@ impl Index { /// If you send an already existing document (same id) the old document will be only partially updated according to the fields of the new document. /// Thus, any fields not present in the new document are kept and remained unchanged. /// - /// To completely overwrite a document, check out the [Index::add_or_replace] documents method. + /// To completely overwrite a document, check out the [`Index::add_or_replace`] documents method. /// /// # Example /// @@ -718,7 +719,7 @@ impl Index { /// If you send an already existing document (same id) the old document will be only partially updated according to the fields of the new document. /// Thus, any fields not present in the new document are kept and remained unchanged. /// - /// To completely overwrite a document, check out the [Index::add_or_replace_unchecked_payload] documents method. + /// To completely overwrite a document, check out the [`Index::add_or_replace_unchecked_payload`] documents method. /// /// # Example /// @@ -926,7 +927,7 @@ impl Index { .await } - /// Alias for the [Index::update] method. + /// Alias for the [`Index::update`] method. pub async fn set_primary_key( &mut self, primary_key: impl AsRef, @@ -938,7 +939,7 @@ impl Index { /// Fetch the information of the index as a raw JSON [Index], this index should already exist. /// - /// If you use it directly from the [Client], you can use the method [Client::get_raw_index], which is the equivalent method from the client. + /// If you use it directly from the [Client], you can use the method [`Client::get_raw_index`], which is the equivalent method from the client. /// /// # Example /// @@ -1145,9 +1146,9 @@ impl Index { /// /// `timeout` = The maximum time to wait for processing to complete. **Default = 5000ms** /// - /// If the waited time exceeds `timeout` then an [Error::Timeout] will be returned. + /// If the waited time exceeds `timeout` then an [`Error::Timeout`] will be returned. /// - /// See also [Client::wait_for_task, Task::wait_for_completion]. + /// See also [`Client::wait_for_task`, `Task::wait_for_completion`]. /// /// # Example /// @@ -1351,7 +1352,7 @@ impl AsRef for Index { } } -/// An [IndexUpdater] used to update the specifics of an index. +/// An [`IndexUpdater`] used to update the specifics of an index. /// /// # Example /// @@ -1404,7 +1405,7 @@ impl<'a> IndexUpdater<'a> { uid: uid.as_ref().to_string(), } } - /// Define the new primary_key to set on the [Index]. + /// Define the new `primary_key` to set on the [Index]. /// /// # Example /// @@ -1446,7 +1447,7 @@ impl<'a> IndexUpdater<'a> { self } - /// Execute the update of an [Index] using the [IndexUpdater]. + /// Execute the update of an [Index] using the [`IndexUpdater`]. /// /// # Example /// @@ -1509,7 +1510,7 @@ impl<'a> AsRef> for IndexUpdater<'a> { } } -#[derive(Deserialize)] +#[derive(Debug, Clone, Deserialize)] #[serde(rename_all = "camelCase")] pub struct IndexStats { pub number_of_documents: usize, @@ -1517,7 +1518,7 @@ pub struct IndexStats { pub field_distribution: HashMap, } -/// An [IndexesQuery] containing filter and pagination parameters when searching for [Indexes](Index). +/// An [`IndexesQuery`] containing filter and pagination parameters when searching for [Indexes](Index). /// /// # Example /// @@ -1574,6 +1575,7 @@ pub struct IndexesQuery<'a> { } impl<'a> IndexesQuery<'a> { + #[must_use] pub fn new(client: &Client) -> IndexesQuery { IndexesQuery { client, diff --git a/src/key.rs b/src/key.rs index de6a507f..154160f3 100644 --- a/src/key.rs +++ b/src/key.rs @@ -5,7 +5,7 @@ use crate::{client::Client, errors::Error}; /// Represents a [meilisearch key](https://docs.meilisearch.com/reference/api/keys.html#returned-fields). /// -/// You can get a [Key] from the [Client::get_key] method, or you can create a [Key] with the [KeyBuilder::new] or [Client::create_key] methods. +/// You can get a [Key] from the [`Client::get_key`] method, or you can create a [Key] with the [`KeyBuilder::new`] or [`Client::create_key`] methods. #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(rename_all = "camelCase")] pub struct Key { @@ -246,7 +246,7 @@ impl KeyUpdater { self } - /// Update a [Key] using the [KeyUpdater]. + /// Update a [Key] using the [`KeyUpdater`]. /// /// # Example /// @@ -310,7 +310,7 @@ pub struct KeysQuery { } impl KeysQuery { - /// Create a [KeysQuery] with only a description. + /// Create a [`KeysQuery`] with only a description. /// /// # Example /// @@ -318,6 +318,7 @@ impl KeysQuery { /// # use meilisearch_sdk::{key::KeysQuery}; /// let builder = KeysQuery::new(); /// ``` + #[must_use] pub fn new() -> KeysQuery { Self::default() } @@ -394,7 +395,7 @@ impl KeysQuery { } } -/// The [KeyBuilder] is an analog to the [Key] type but without all the fields managed by Meilisearch. +/// The [`KeyBuilder`] is an analog to the [Key] type but without all the fields managed by Meilisearch. /// /// It's used to create [Key]. /// @@ -417,7 +418,7 @@ impl KeysQuery { /// # client.delete_key(key).await.unwrap(); /// # }); /// ``` -#[derive(Debug, Serialize, Default)] +#[derive(Debug, Clone, Serialize, Default)] #[serde(rename_all = "camelCase")] pub struct KeyBuilder { pub actions: Vec, @@ -433,7 +434,7 @@ pub struct KeyBuilder { } impl KeyBuilder { - /// Create a [KeyBuilder]. + /// Create a [`KeyBuilder`]. /// /// # Example /// @@ -441,6 +442,7 @@ impl KeyBuilder { /// # use meilisearch_sdk::{key::KeyBuilder}; /// let builder = KeyBuilder::new(); /// ``` + #[must_use] pub fn new() -> KeyBuilder { Self::default() } diff --git a/src/lib.rs b/src/lib.rs index 4087068b..3cfed4c6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -223,26 +223,26 @@ #![warn(clippy::all)] #![allow(clippy::needless_doctest_main)] -/// Module containing the [client::Client] struct. +/// Module containing the [`client::Client`] struct. pub mod client; /// Module representing the [documents] structures. pub mod documents; /// Module containing the [dumps] trait. pub mod dumps; -/// Module containing the [errors::Error] struct. +/// Module containing the [`errors::Error`] struct. pub mod errors; /// Module containing the Index struct. pub mod indexes; -/// Module containing the [key::Key] struct. +/// Module containing the [`key::Key`] struct. pub mod key; mod request; /// Module related to search queries and results. pub mod search; -/// Module containing [settings::Settings]. +/// Module containing [`settings::Settings`]. pub mod settings; -/// Module representing the [task_info::TaskInfo]s. +/// Module representing the [`task_info::TaskInfo`]s. pub mod task_info; -/// Module representing the [tasks::Task]s. +/// Module representing the [`tasks::Task`]s. pub mod tasks; /// Module that generates tenant tokens. mod tenant_tokens; diff --git a/src/request.rs b/src/request.rs index 6015e437..2a6e474b 100644 --- a/src/request.rs +++ b/src/request.rs @@ -116,7 +116,7 @@ pub(crate) async fn request< body = "null".to_string(); } - parse_response(status, expected_status_code, body) + parse_response(status, expected_status_code, &body) } #[cfg(not(target_arch = "wasm32"))] @@ -214,7 +214,7 @@ pub(crate) async fn stream_request< body = "null".to_string(); } - parse_response(status, expected_status_code, body) + parse_response(status, expected_status_code, &body) } #[cfg(target_arch = "wasm32")] @@ -318,9 +318,9 @@ pub(crate) async fn request< if let Some(t) = text.as_string() { if t.is_empty() { - parse_response(status, expected_status_code, String::from("null")) + parse_response(status, expected_status_code, "null") } else { - parse_response(status, expected_status_code, t) + parse_response(status, expected_status_code, &t) } } else { error!("Invalid response"); @@ -331,10 +331,10 @@ pub(crate) async fn request< fn parse_response( status_code: u16, expected_status_code: u16, - body: String, + body: &str, ) -> Result { if status_code == expected_status_code { - match from_str::(&body) { + match from_str::(body) { Ok(output) => { trace!("Request succeed"); return Ok(output); @@ -352,7 +352,7 @@ fn parse_response( "Expected response code {}, got {}", expected_status_code, status_code ); - match from_str::(&body) { + match from_str::(body) { Ok(e) => Err(Error::from(e)), Err(e) => Err(Error::ParseError(e)), } diff --git a/src/search.rs b/src/search.rs index 4784618a..4f879b83 100644 --- a/src/search.rs +++ b/src/search.rs @@ -18,6 +18,7 @@ pub struct Filter<'a> { } impl<'a> Filter<'a> { + #[must_use] pub fn new(inner: Either<&'a str, Vec<&'a str>>) -> Filter { Filter { inner } } @@ -47,13 +48,13 @@ pub struct SearchResult { pub matches_position: Option>>, } -#[derive(Deserialize, Debug)] +#[derive(Deserialize, Debug, Clone)] #[serde(rename_all = "camelCase")] pub struct FacetStats { pub min: u32, pub max: u32, } -#[derive(Deserialize, Debug)] +#[derive(Deserialize, Debug, Clone)] #[serde(rename_all = "camelCase")] /// A struct containing search results and other information about the search. pub struct SearchResults { @@ -111,7 +112,7 @@ fn serialize_attributes_to_crop_with_wildcard( result.push(':'); result.push_str(value.to_string().as_str()); } - results.push(result) + results.push(result); } results.serialize(s) } @@ -311,6 +312,7 @@ pub struct SearchQuery<'a> { #[allow(missing_docs)] impl<'a> SearchQuery<'a> { + #[must_use] pub fn new(index: &'a Index) -> SearchQuery<'a> { SearchQuery { index, @@ -490,7 +492,8 @@ impl<'a> SearchQuery<'a> { self.index_uid = Some(&self.index.uid); self } - pub fn build(&mut self) -> SearchQuery<'a> { + #[must_use] + pub fn build(&mut self) -> Self { self.clone() } /// Execute the query and fetch the results. @@ -511,6 +514,7 @@ pub struct MultiSearchQuery<'a, 'b> { #[allow(missing_docs)] impl<'a, 'b> MultiSearchQuery<'a, 'b> { + #[must_use] pub fn new(client: &'a Client) -> MultiSearchQuery<'a, 'b> { MultiSearchQuery { client, @@ -533,7 +537,7 @@ impl<'a, 'b> MultiSearchQuery<'a, 'b> { self.client.execute_multi_search_query::(self).await } } -#[derive(Debug, Deserialize)] +#[derive(Debug, Clone, Deserialize)] pub struct MultiSearchResponse { pub results: Vec>, } diff --git a/src/settings.rs b/src/settings.rs index 8ba35cfa..ecadd93f 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -13,7 +13,7 @@ pub struct PaginationSetting { pub max_total_hits: usize, } -#[derive(Serialize, Deserialize, Default, Debug, Clone, Eq, PartialEq)] +#[derive(Serialize, Deserialize, Default, Debug, Clone, Eq, PartialEq, Copy)] #[serde(rename_all = "camelCase")] pub struct FacetingSettings { pub max_values_per_facet: usize, @@ -82,8 +82,9 @@ pub struct Settings { #[allow(missing_docs)] impl Settings { /// Create undefined settings. - pub fn new() -> Settings { - Settings { + #[must_use] + pub fn new() -> Self { + Self { synonyms: None, stop_words: None, ranking_rules: None, @@ -96,13 +97,15 @@ impl Settings { faceting: None, } } - pub fn with_synonyms(self, synonyms: HashMap) -> Settings + + #[must_use] + pub fn with_synonyms(self, synonyms: HashMap) -> Self where S: AsRef, V: AsRef, U: IntoIterator, { - Settings { + Self { synonyms: Some( synonyms .into_iter() @@ -118,11 +121,9 @@ impl Settings { } } - pub fn with_stop_words( - self, - stop_words: impl IntoIterator>, - ) -> Settings { - Settings { + #[must_use] + pub fn with_stop_words(self, stop_words: impl IntoIterator>) -> Self { + Self { stop_words: Some( stop_words .into_iter() @@ -133,18 +134,20 @@ impl Settings { } } - pub fn with_pagination(self, pagination_settings: PaginationSetting) -> Settings { - Settings { + #[must_use] + pub fn with_pagination(self, pagination_settings: PaginationSetting) -> Self { + Self { pagination: Some(pagination_settings), ..self } } + #[must_use] pub fn with_ranking_rules( self, ranking_rules: impl IntoIterator>, - ) -> Settings { - Settings { + ) -> Self { + Self { ranking_rules: Some( ranking_rules .into_iter() @@ -155,11 +158,12 @@ impl Settings { } } + #[must_use] pub fn with_filterable_attributes( self, filterable_attributes: impl IntoIterator>, - ) -> Settings { - Settings { + ) -> Self { + Self { filterable_attributes: Some( filterable_attributes .into_iter() @@ -170,11 +174,12 @@ impl Settings { } } + #[must_use] pub fn with_sortable_attributes( self, sortable_attributes: impl IntoIterator>, - ) -> Settings { - Settings { + ) -> Self { + Self { sortable_attributes: Some( sortable_attributes .into_iter() @@ -185,18 +190,20 @@ impl Settings { } } - pub fn with_distinct_attribute(self, distinct_attribute: impl AsRef) -> Settings { - Settings { + #[must_use] + pub fn with_distinct_attribute(self, distinct_attribute: impl AsRef) -> Self { + Self { distinct_attribute: Some(distinct_attribute.as_ref().to_string()), ..self } } + #[must_use] pub fn with_searchable_attributes( self, searchable_attributes: impl IntoIterator>, - ) -> Settings { - Settings { + ) -> Self { + Self { searchable_attributes: Some( searchable_attributes .into_iter() @@ -207,11 +214,12 @@ impl Settings { } } + #[must_use] pub fn with_displayed_attributes( self, displayed_attributes: impl IntoIterator>, - ) -> Settings { - Settings { + ) -> Self { + Self { displayed_attributes: Some( displayed_attributes .into_iter() @@ -222,9 +230,10 @@ impl Settings { } } - pub fn with_faceting(self, faceting: &FacetingSettings) -> Settings { - Settings { - faceting: Some(faceting.clone()), + #[must_use] + pub fn with_faceting(self, faceting: &FacetingSettings) -> Self { + Self { + faceting: Some(*faceting), ..self } } diff --git a/src/task_info.rs b/src/task_info.rs index 28f79f34..549787c4 100644 --- a/src/task_info.rs +++ b/src/task_info.rs @@ -23,19 +23,20 @@ impl AsRef for TaskInfo { } impl TaskInfo { + #[must_use] pub fn get_task_uid(&self) -> u32 { self.task_uid } - /// Wait until Meilisearch processes a task provided by [TaskInfo], and get its status. + /// Wait until Meilisearch processes a task provided by [`TaskInfo`], and get its status. /// /// `interval` = The frequency at which the server should be polled. **Default = 50ms** /// /// `timeout` = The maximum time to wait for processing to complete. **Default = 5000ms** /// - /// If the waited time exceeds `timeout` then an [Error::Timeout] will be returned. + /// If the waited time exceeds `timeout` then an [`Error::Timeout`] will be returned. /// - /// See also [Client::wait_for_task, Index::wait_for_task]. + /// See also [`Client::wait_for_task`, `Index::wait_for_task`]. /// /// # Example /// diff --git a/src/tasks.rs b/src/tasks.rs index 95509609..02577ade 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -205,6 +205,7 @@ pub enum Task { } impl Task { + #[must_use] pub fn get_uid(&self) -> u32 { match self { Self::Enqueued { content } | Self::Processing { content } => *content.as_ref(), @@ -219,9 +220,9 @@ impl Task { /// /// `timeout` = The maximum time to wait for processing to complete. **Default = 5000ms** /// - /// If the waited time exceeds `timeout` then an [Error::Timeout] will be returned. + /// If the waited time exceeds `timeout` then an [`Error::Timeout`] will be returned. /// - /// See also [Client::wait_for_task, Index::wait_for_task]. + /// See also [`Client::wait_for_task`, `Index::wait_for_task`]. /// /// # Example /// @@ -305,9 +306,9 @@ impl Task { } } - /// Unwrap the [MeilisearchError] from a [Self::Failed] [Task]. + /// Unwrap the [`MeilisearchError`] from a [`Self::Failed`] [Task]. /// - /// Will panic if the task was not [Self::Failed]. + /// Will panic if the task was not [`Self::Failed`]. /// /// # Example /// @@ -336,6 +337,7 @@ impl Task { /// # client.index("unwrap_failure").delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` + #[must_use] pub fn unwrap_failure(self) -> MeilisearchError { match self { Self::Failed { @@ -345,7 +347,7 @@ impl Task { } } - /// Returns `true` if the [Task] is [Self::Failed]. + /// Returns `true` if the [Task] is [`Self::Failed`]. /// /// # Example /// @@ -371,11 +373,12 @@ impl Task { /// # client.index("is_failure").delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` + #[must_use] pub fn is_failure(&self) -> bool { matches!(self, Self::Failed { .. }) } - /// Returns `true` if the [Task] is [Self::Succeeded]. + /// Returns `true` if the [Task] is [`Self::Succeeded`]. /// /// # Example /// @@ -399,11 +402,12 @@ impl Task { /// # task.try_make_index(&client).unwrap().delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` + #[must_use] pub fn is_success(&self) -> bool { matches!(self, Self::Succeeded { .. }) } - /// Returns `true` if the [Task] is pending ([Self::Enqueued] or [Self::Processing]). + /// Returns `true` if the [Task] is pending ([`Self::Enqueued`] or [`Self::Processing`]). /// /// # Example /// ```no_run @@ -426,6 +430,7 @@ impl Task { /// # task.wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap().delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` + #[must_use] pub fn is_pending(&self) -> bool { matches!(self, Self::Enqueued { .. } | Self::Processing { .. }) } @@ -604,6 +609,7 @@ impl<'a, T> TasksQuery<'a, T> { } impl<'a> TasksQuery<'a, TasksCancelFilters> { + #[must_use] pub fn new(client: &'a Client) -> TasksQuery<'a, TasksCancelFilters> { TasksQuery { client, @@ -628,6 +634,7 @@ impl<'a> TasksQuery<'a, TasksCancelFilters> { } impl<'a> TasksQuery<'a, TasksDeleteFilters> { + #[must_use] pub fn new(client: &'a Client) -> TasksQuery<'a, TasksDeleteFilters> { TasksQuery { client, @@ -652,6 +659,7 @@ impl<'a> TasksQuery<'a, TasksDeleteFilters> { } impl<'a> TasksQuery<'a, TasksPaginationFilters> { + #[must_use] pub fn new(client: &'a Client) -> TasksQuery<'a, TasksPaginationFilters> { TasksQuery { client, diff --git a/src/tenant_tokens.rs b/src/tenant_tokens.rs index 747fae8b..ea9bab98 100644 --- a/src/tenant_tokens.rs +++ b/src/tenant_tokens.rs @@ -94,7 +94,7 @@ mod tests { fn test_generate_token_without_uid() { let api_key_uid = S(""); let key = S(""); - let token = generate_tenant_token(api_key_uid, json!(SEARCH_RULES), &key, None); + let token = generate_tenant_token(api_key_uid, json!(SEARCH_RULES), key, None); assert!(token.is_err()); } @@ -163,7 +163,7 @@ mod tests { fn test_generate_token_with_wrongly_formated_uid() { let api_key_uid = S("xxx"); let key = "Ëa1ทt9bVcL-vãUทtP3OpXW5qPc%bWH5ทvw09"; - let token = generate_tenant_token(api_key_uid.clone(), json!(SEARCH_RULES), key, None); + let token = generate_tenant_token(api_key_uid, json!(SEARCH_RULES), key, None); assert!(token.is_err()); } @@ -172,7 +172,7 @@ mod tests { fn test_generate_token_with_wrong_uid_version() { let api_key_uid = S("6a11eb96-2485-11ed-861d-0242ac120002"); let key = "Ëa1ทt9bVcL-vãUทtP3OpXW5qPc%bWH5ทvw09"; - let token = generate_tenant_token(api_key_uid.clone(), json!(SEARCH_RULES), key, None); + let token = generate_tenant_token(api_key_uid, json!(SEARCH_RULES), key, None); assert!(token.is_err()); } From e891ae0270d589d4e1572bbedd1cfe06a9042d99 Mon Sep 17 00:00:00 2001 From: Omid Rad Date: Mon, 15 May 2023 17:24:46 +0200 Subject: [PATCH 2/5] Remove must_use and -> Self --- src/client.rs | 3 --- src/documents.rs | 3 --- src/indexes.rs | 2 -- src/key.rs | 2 -- src/search.rs | 6 +----- src/settings.rs | 33 +++++++++++---------------------- src/tasks.rs | 8 -------- 7 files changed, 12 insertions(+), 45 deletions(-) diff --git a/src/client.rs b/src/client.rs index 57e2655d..9f625166 100644 --- a/src/client.rs +++ b/src/client.rs @@ -121,7 +121,6 @@ impl Client { /// # movies.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` - #[must_use] pub fn multi_search(&self) -> MultiSearchQuery { MultiSearchQuery::new(self) } @@ -137,7 +136,6 @@ impl Client { /// /// assert_eq!(client.get_host(), "http://doggo.dog"); /// ``` - #[must_use] pub fn get_host(&self) -> &str { &self.host } @@ -153,7 +151,6 @@ impl Client { /// /// assert_eq!(client.get_api_key(), Some("doggo")); /// ``` - #[must_use] pub fn get_api_key(&self) -> Option<&str> { self.api_key.as_deref() } diff --git a/src/documents.rs b/src/documents.rs index ec7e6a1c..79c31856 100644 --- a/src/documents.rs +++ b/src/documents.rs @@ -56,7 +56,6 @@ use crate::{errors::Error, indexes::Index}; pub trait IndexConfig { const INDEX_STR: &'static str; - #[must_use] fn index(client: &Client) -> Index { client.index(Self::INDEX_STR) } @@ -83,7 +82,6 @@ pub struct DocumentQuery<'a> { } impl<'a> DocumentQuery<'a> { - #[must_use] pub fn new(index: &Index) -> DocumentQuery { DocumentQuery { index, @@ -190,7 +188,6 @@ pub struct DocumentsQuery<'a> { } impl<'a> DocumentsQuery<'a> { - #[must_use] pub fn new(index: &Index) -> DocumentsQuery { DocumentsQuery { index, diff --git a/src/indexes.rs b/src/indexes.rs index 4b870f01..69c4168a 100644 --- a/src/indexes.rs +++ b/src/indexes.rs @@ -268,7 +268,6 @@ impl Index { /// # movies.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` - #[must_use] pub fn search(&self) -> SearchQuery { SearchQuery::new(self) } @@ -1575,7 +1574,6 @@ pub struct IndexesQuery<'a> { } impl<'a> IndexesQuery<'a> { - #[must_use] pub fn new(client: &Client) -> IndexesQuery { IndexesQuery { client, diff --git a/src/key.rs b/src/key.rs index 154160f3..724422f4 100644 --- a/src/key.rs +++ b/src/key.rs @@ -318,7 +318,6 @@ impl KeysQuery { /// # use meilisearch_sdk::{key::KeysQuery}; /// let builder = KeysQuery::new(); /// ``` - #[must_use] pub fn new() -> KeysQuery { Self::default() } @@ -442,7 +441,6 @@ impl KeyBuilder { /// # use meilisearch_sdk::{key::KeyBuilder}; /// let builder = KeyBuilder::new(); /// ``` - #[must_use] pub fn new() -> KeyBuilder { Self::default() } diff --git a/src/search.rs b/src/search.rs index 4f879b83..dfac0c57 100644 --- a/src/search.rs +++ b/src/search.rs @@ -18,7 +18,6 @@ pub struct Filter<'a> { } impl<'a> Filter<'a> { - #[must_use] pub fn new(inner: Either<&'a str, Vec<&'a str>>) -> Filter { Filter { inner } } @@ -312,7 +311,6 @@ pub struct SearchQuery<'a> { #[allow(missing_docs)] impl<'a> SearchQuery<'a> { - #[must_use] pub fn new(index: &'a Index) -> SearchQuery<'a> { SearchQuery { index, @@ -492,8 +490,7 @@ impl<'a> SearchQuery<'a> { self.index_uid = Some(&self.index.uid); self } - #[must_use] - pub fn build(&mut self) -> Self { + pub fn build(&mut self) -> SearchQuery<'a> { self.clone() } /// Execute the query and fetch the results. @@ -514,7 +511,6 @@ pub struct MultiSearchQuery<'a, 'b> { #[allow(missing_docs)] impl<'a, 'b> MultiSearchQuery<'a, 'b> { - #[must_use] pub fn new(client: &'a Client) -> MultiSearchQuery<'a, 'b> { MultiSearchQuery { client, diff --git a/src/settings.rs b/src/settings.rs index ecadd93f..af8ab4dc 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -82,8 +82,7 @@ pub struct Settings { #[allow(missing_docs)] impl Settings { /// Create undefined settings. - #[must_use] - pub fn new() -> Self { + pub fn new() -> Settings { Self { synonyms: None, stop_words: None, @@ -98,8 +97,7 @@ impl Settings { } } - #[must_use] - pub fn with_synonyms(self, synonyms: HashMap) -> Self + pub fn with_synonyms(self, synonyms: HashMap) -> Settings where S: AsRef, V: AsRef, @@ -121,8 +119,7 @@ impl Settings { } } - #[must_use] - pub fn with_stop_words(self, stop_words: impl IntoIterator>) -> Self { + pub fn with_stop_words(self, stop_words: impl IntoIterator>) -> Settings { Self { stop_words: Some( stop_words @@ -134,19 +131,17 @@ impl Settings { } } - #[must_use] - pub fn with_pagination(self, pagination_settings: PaginationSetting) -> Self { + pub fn with_pagination(self, pagination_settings: PaginationSetting) -> Settings { Self { pagination: Some(pagination_settings), ..self } } - #[must_use] pub fn with_ranking_rules( self, ranking_rules: impl IntoIterator>, - ) -> Self { + ) -> Settings { Self { ranking_rules: Some( ranking_rules @@ -158,11 +153,10 @@ impl Settings { } } - #[must_use] pub fn with_filterable_attributes( self, filterable_attributes: impl IntoIterator>, - ) -> Self { + ) -> Settings { Self { filterable_attributes: Some( filterable_attributes @@ -174,11 +168,10 @@ impl Settings { } } - #[must_use] pub fn with_sortable_attributes( self, sortable_attributes: impl IntoIterator>, - ) -> Self { + ) -> Settings { Self { sortable_attributes: Some( sortable_attributes @@ -190,19 +183,17 @@ impl Settings { } } - #[must_use] - pub fn with_distinct_attribute(self, distinct_attribute: impl AsRef) -> Self { + pub fn with_distinct_attribute(self, distinct_attribute: impl AsRef) -> Settings { Self { distinct_attribute: Some(distinct_attribute.as_ref().to_string()), ..self } } - #[must_use] pub fn with_searchable_attributes( self, searchable_attributes: impl IntoIterator>, - ) -> Self { + ) -> Settings { Self { searchable_attributes: Some( searchable_attributes @@ -214,11 +205,10 @@ impl Settings { } } - #[must_use] pub fn with_displayed_attributes( self, displayed_attributes: impl IntoIterator>, - ) -> Self { + ) -> Settings { Self { displayed_attributes: Some( displayed_attributes @@ -230,8 +220,7 @@ impl Settings { } } - #[must_use] - pub fn with_faceting(self, faceting: &FacetingSettings) -> Self { + pub fn with_faceting(self, faceting: &FacetingSettings) -> Settings { Self { faceting: Some(*faceting), ..self diff --git a/src/tasks.rs b/src/tasks.rs index 02577ade..21a816f7 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -205,7 +205,6 @@ pub enum Task { } impl Task { - #[must_use] pub fn get_uid(&self) -> u32 { match self { Self::Enqueued { content } | Self::Processing { content } => *content.as_ref(), @@ -337,7 +336,6 @@ impl Task { /// # client.index("unwrap_failure").delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` - #[must_use] pub fn unwrap_failure(self) -> MeilisearchError { match self { Self::Failed { @@ -373,7 +371,6 @@ impl Task { /// # client.index("is_failure").delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` - #[must_use] pub fn is_failure(&self) -> bool { matches!(self, Self::Failed { .. }) } @@ -402,7 +399,6 @@ impl Task { /// # task.try_make_index(&client).unwrap().delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` - #[must_use] pub fn is_success(&self) -> bool { matches!(self, Self::Succeeded { .. }) } @@ -430,7 +426,6 @@ impl Task { /// # task.wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap().delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` - #[must_use] pub fn is_pending(&self) -> bool { matches!(self, Self::Enqueued { .. } | Self::Processing { .. }) } @@ -609,7 +604,6 @@ impl<'a, T> TasksQuery<'a, T> { } impl<'a> TasksQuery<'a, TasksCancelFilters> { - #[must_use] pub fn new(client: &'a Client) -> TasksQuery<'a, TasksCancelFilters> { TasksQuery { client, @@ -634,7 +628,6 @@ impl<'a> TasksQuery<'a, TasksCancelFilters> { } impl<'a> TasksQuery<'a, TasksDeleteFilters> { - #[must_use] pub fn new(client: &'a Client) -> TasksQuery<'a, TasksDeleteFilters> { TasksQuery { client, @@ -659,7 +652,6 @@ impl<'a> TasksQuery<'a, TasksDeleteFilters> { } impl<'a> TasksQuery<'a, TasksPaginationFilters> { - #[must_use] pub fn new(client: &'a Client) -> TasksQuery<'a, TasksPaginationFilters> { TasksQuery { client, From 7d57737252cc348c53c1eb6daa38f7eb5dfffb39 Mon Sep 17 00:00:00 2001 From: Omid Rad Date: Mon, 15 May 2023 17:28:08 +0200 Subject: [PATCH 3/5] remaining `Self`s --- examples/web_app/src/lib.rs | 2 +- src/indexes.rs | 2 +- src/key.rs | 24 ++++++++++++------------ src/settings.rs | 22 +++++++++++----------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/examples/web_app/src/lib.rs b/examples/web_app/src/lib.rs index 8d5a1e87..99e1de65 100644 --- a/examples/web_app/src/lib.rs +++ b/examples/web_app/src/lib.rs @@ -44,7 +44,7 @@ impl Component for Model { type Message = Msg; type Properties = (); fn create(_ctx: &Context) -> Model { - Self { + Model { // The index method avoids checking the existence of the index. // It won't make any HTTP request so the function is not async so it's easier to use. // Use only if you are sure that the index exists. diff --git a/src/indexes.rs b/src/indexes.rs index 69c4168a..441dc5a8 100644 --- a/src/indexes.rs +++ b/src/indexes.rs @@ -1441,7 +1441,7 @@ impl<'a> IndexUpdater<'a> { /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` - pub fn with_primary_key(&mut self, primary_key: impl AsRef) -> &mut Self { + pub fn with_primary_key(&mut self, primary_key: impl AsRef) -> &mut IndexUpdater<'a> { self.primary_key = Some(primary_key.as_ref().to_string()); self } diff --git a/src/key.rs b/src/key.rs index 724422f4..b0905e87 100644 --- a/src/key.rs +++ b/src/key.rs @@ -51,7 +51,7 @@ impl Key { /// # client.delete_key(key).await.unwrap(); /// # }); /// ``` - pub fn with_description(&mut self, desc: impl AsRef) -> &mut Self { + pub fn with_description(&mut self, desc: impl AsRef) -> &mut Key { self.description = Some(desc.as_ref().to_string()); self } @@ -82,7 +82,7 @@ impl Key { /// # client.delete_key(key).await.unwrap(); /// # }); /// ``` - pub fn with_name(&mut self, desc: impl AsRef) -> &mut Self { + pub fn with_name(&mut self, desc: impl AsRef) -> &mut Key { self.name = Some(desc.as_ref().to_string()); self } @@ -208,7 +208,7 @@ impl KeyUpdater { /// # client.delete_key(key_update).await.unwrap(); /// # }); /// ``` - pub fn with_description(&mut self, desc: impl AsRef) -> &mut Self { + pub fn with_description(&mut self, desc: impl AsRef) -> &mut KeyUpdater { self.description = Some(desc.as_ref().to_string()); self } @@ -241,7 +241,7 @@ impl KeyUpdater { /// # client.delete_key(key_update).await.unwrap(); /// # }); /// ``` - pub fn with_name(&mut self, desc: impl AsRef) -> &mut Self { + pub fn with_name(&mut self, desc: impl AsRef) -> &mut KeyUpdater { self.name = Some(desc.as_ref().to_string()); self } @@ -454,7 +454,7 @@ impl KeyBuilder { /// let mut builder = KeyBuilder::new(); /// builder.with_actions(vec![Action::Search, Action::DocumentsAdd]); /// ``` - pub fn with_actions(&mut self, actions: impl IntoIterator) -> &mut Self { + pub fn with_actions(&mut self, actions: impl IntoIterator) -> &mut KeyBuilder { self.actions.extend(actions); self } @@ -468,7 +468,7 @@ impl KeyBuilder { /// let mut builder = KeyBuilder::new(); /// builder.with_action(Action::DocumentsAdd); /// ``` - pub fn with_action(&mut self, action: Action) -> &mut Self { + pub fn with_action(&mut self, action: Action) -> &mut KeyBuilder { self.actions.push(action); self } @@ -484,7 +484,7 @@ impl KeyBuilder { /// // create a key that expires in two weeks from now /// builder.with_expires_at(OffsetDateTime::now_utc() + Duration::WEEK * 2); /// ``` - pub fn with_expires_at(&mut self, expires_at: OffsetDateTime) -> &mut Self { + pub fn with_expires_at(&mut self, expires_at: OffsetDateTime) -> &mut KeyBuilder { self.expires_at = Some(expires_at); self } @@ -514,7 +514,7 @@ impl KeyBuilder { pub fn with_indexes( &mut self, indexes: impl IntoIterator>, - ) -> &mut Self { + ) -> &mut KeyBuilder { self.indexes = indexes .into_iter() .map(|index| index.as_ref().to_string()) @@ -531,7 +531,7 @@ impl KeyBuilder { /// let mut builder = KeyBuilder::new(); /// builder.with_index("test"); /// ``` - pub fn with_index(&mut self, index: impl AsRef) -> &mut Self { + pub fn with_index(&mut self, index: impl AsRef) -> &mut KeyBuilder { self.indexes.push(index.as_ref().to_string()); self } @@ -557,7 +557,7 @@ impl KeyBuilder { /// # client.delete_key(key).await.unwrap(); /// # }); /// ``` - pub fn with_description(&mut self, desc: impl AsRef) -> &mut Self { + pub fn with_description(&mut self, desc: impl AsRef) -> &mut KeyBuilder { self.description = Some(desc.as_ref().to_string()); self } @@ -583,7 +583,7 @@ impl KeyBuilder { /// # client.delete_key(key).await.unwrap(); /// # }); /// ``` - pub fn with_name(&mut self, desc: impl AsRef) -> &mut Self { + pub fn with_name(&mut self, desc: impl AsRef) -> &mut KeyBuilder { self.name = Some(desc.as_ref().to_string()); self } @@ -609,7 +609,7 @@ impl KeyBuilder { /// # client.delete_key(key).await.unwrap(); /// # }); /// ``` - pub fn with_uid(&mut self, desc: impl AsRef) -> &mut Self { + pub fn with_uid(&mut self, desc: impl AsRef) -> &mut KeyBuilder { self.uid = Some(desc.as_ref().to_string()); self } diff --git a/src/settings.rs b/src/settings.rs index af8ab4dc..11969e20 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -83,7 +83,7 @@ pub struct Settings { impl Settings { /// Create undefined settings. pub fn new() -> Settings { - Self { + Settings { synonyms: None, stop_words: None, ranking_rules: None, @@ -103,7 +103,7 @@ impl Settings { V: AsRef, U: IntoIterator, { - Self { + Settings { synonyms: Some( synonyms .into_iter() @@ -120,7 +120,7 @@ impl Settings { } pub fn with_stop_words(self, stop_words: impl IntoIterator>) -> Settings { - Self { + Settings { stop_words: Some( stop_words .into_iter() @@ -132,7 +132,7 @@ impl Settings { } pub fn with_pagination(self, pagination_settings: PaginationSetting) -> Settings { - Self { + Settings { pagination: Some(pagination_settings), ..self } @@ -142,7 +142,7 @@ impl Settings { self, ranking_rules: impl IntoIterator>, ) -> Settings { - Self { + Settings { ranking_rules: Some( ranking_rules .into_iter() @@ -157,7 +157,7 @@ impl Settings { self, filterable_attributes: impl IntoIterator>, ) -> Settings { - Self { + Settings { filterable_attributes: Some( filterable_attributes .into_iter() @@ -172,7 +172,7 @@ impl Settings { self, sortable_attributes: impl IntoIterator>, ) -> Settings { - Self { + Settings { sortable_attributes: Some( sortable_attributes .into_iter() @@ -184,7 +184,7 @@ impl Settings { } pub fn with_distinct_attribute(self, distinct_attribute: impl AsRef) -> Settings { - Self { + Settings { distinct_attribute: Some(distinct_attribute.as_ref().to_string()), ..self } @@ -194,7 +194,7 @@ impl Settings { self, searchable_attributes: impl IntoIterator>, ) -> Settings { - Self { + Settings { searchable_attributes: Some( searchable_attributes .into_iter() @@ -209,7 +209,7 @@ impl Settings { self, displayed_attributes: impl IntoIterator>, ) -> Settings { - Self { + Settings { displayed_attributes: Some( displayed_attributes .into_iter() @@ -221,7 +221,7 @@ impl Settings { } pub fn with_faceting(self, faceting: &FacetingSettings) -> Settings { - Self { + Settings { faceting: Some(*faceting), ..self } From b92c7f19c21bd7a69c000bce91134cb510a7d2ef Mon Sep 17 00:00:00 2001 From: Omid Rad Date: Mon, 15 May 2023 18:15:54 +0200 Subject: [PATCH 4/5] Update src/task_info.rs Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com> --- src/task_info.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/task_info.rs b/src/task_info.rs index 549787c4..a864b9c2 100644 --- a/src/task_info.rs +++ b/src/task_info.rs @@ -23,7 +23,6 @@ impl AsRef for TaskInfo { } impl TaskInfo { - #[must_use] pub fn get_task_uid(&self) -> u32 { self.task_uid } From 39b91b0bbbcb3ba621c9c13579ab883a7d07292f Mon Sep 17 00:00:00 2001 From: Omid Rad Date: Mon, 15 May 2023 18:16:27 +0200 Subject: [PATCH 5/5] cargo fmt --- src/settings.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/settings.rs b/src/settings.rs index 11969e20..ab0ea97b 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -119,7 +119,10 @@ impl Settings { } } - pub fn with_stop_words(self, stop_words: impl IntoIterator>) -> Settings { + pub fn with_stop_words( + self, + stop_words: impl IntoIterator>, + ) -> Settings { Settings { stop_words: Some( stop_words