Skip to content

Add Debug and Clone to all public API structs, and some CS #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions examples/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
);
}
2 changes: 1 addition & 1 deletion examples/web_app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Component for Model {
type Message = Msg;
type Properties = ();
fn create(_ctx: &Context<Self>) -> 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.
Expand Down
48 changes: 24 additions & 24 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ impl Client {
pub fn new(host: impl Into<String>, api_key: Option<impl Into<String>>) -> 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<IndexesResults, Error> {
fn parse_indexes_results_from_value(&self, value: &Value) -> Result<IndexesResults, Error> {
let raw_indexes = value["results"].as_array().unwrap();

let indexes_results = IndexesResults {
Expand Down Expand Up @@ -174,7 +174,7 @@ impl Client {
/// ```
pub async fn list_all_indexes(&self) -> Result<IndexesResults, Error> {
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)
}

Expand Down Expand Up @@ -203,7 +203,7 @@ impl Client {
indexes_query: &IndexesQuery<'_>,
) -> Result<IndexesResults, Error> {
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)
}
Expand Down Expand Up @@ -301,7 +301,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
///
Expand Down Expand Up @@ -385,7 +385,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<str>) -> Result<TaskInfo, Error> {
request::<(), (), TaskInfo>(
&format!("{}/indexes/{}", self.host, uid.as_ref()),
Expand All @@ -396,25 +396,25 @@ impl Client {
.await
}

/// Alias for [Client::list_all_indexes].
/// Alias for [`Client::list_all_indexes`].
pub async fn get_indexes(&self) -> Result<IndexesResults, Error> {
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<'_>,
) -> Result<IndexesResults, Error> {
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<Value, Error> {
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<'_>,
Expand Down Expand Up @@ -549,7 +549,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
///
Expand Down Expand Up @@ -583,7 +583,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
///
Expand Down Expand Up @@ -614,7 +614,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
///
Expand Down Expand Up @@ -646,7 +646,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
///
Expand Down Expand Up @@ -681,7 +681,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
///
Expand Down Expand Up @@ -718,7 +718,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
///
Expand Down Expand Up @@ -787,9 +787,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
///
Expand Down Expand Up @@ -917,7 +917,7 @@ impl Client {
Ok(tasks)
}

/// Cancel tasks with filters [TasksCancelQuery].
/// Cancel tasks with filters [`TasksCancelQuery`].
///
/// # Example
///
Expand Down Expand Up @@ -953,7 +953,7 @@ impl Client {
Ok(tasks)
}

/// Delete tasks with filters [TasksDeleteQuery].
/// Delete tasks with filters [`TasksDeleteQuery`].
///
/// # Example
///
Expand Down Expand Up @@ -1054,7 +1054,7 @@ impl Client {
}
}

#[derive(Deserialize)]
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ClientStats {
pub database_size: usize,
Expand All @@ -1073,7 +1073,7 @@ pub struct ClientStats {
/// status: "available".to_string(),
/// };
/// ```
#[derive(Deserialize)]
#[derive(Debug, Clone, Deserialize)]
pub struct Health {
pub status: String,
}
Expand All @@ -1090,7 +1090,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,
Expand Down Expand Up @@ -1331,7 +1331,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();
Expand Down
2 changes: 1 addition & 1 deletion src/dumps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TaskInfo, Error> {
client.create_dump().await
}
Expand Down
Loading