Skip to content

refactor: resolve clippy warnings and apply idiomatic rust patterns#108

Open
marlon-costa-dc wants to merge 1 commit into
milvus-io:mainfrom
marlon-costa-dc:refactor/clippy-and-idiomatic-fixes
Open

refactor: resolve clippy warnings and apply idiomatic rust patterns#108
marlon-costa-dc wants to merge 1 commit into
milvus-io:mainfrom
marlon-costa-dc:refactor/clippy-and-idiomatic-fixes

Conversation

@marlon-costa-dc
Copy link
Copy Markdown

Summary

  • Resolves various clippy warnings across the codebase.
  • Replaces push_str(",") with push(',').
  • Uses matches!() macro where appropriate.
  • Adds is_empty() method to FieldColumn.
  • Removes redundant manual Default implementations in favor of #[derive(Default)].
  • Simplifies struct initializations (field init shorthand).

@sre-ci-robot
Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: marlon-costa-dc
To complete the pull request process, please assign congqixia after the PR has been reviewed.
You can assign the PR to them by writing /assign @congqixia in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@mergify
Copy link
Copy Markdown

mergify Bot commented Feb 25, 2026

@marlon-costa-dc Thanks for your contribution. Please submit with DCO, see the contributing guide https://github.com/milvus-io/milvus/blob/master/CONTRIBUTING.md#developer-certificate-of-origin-dco.

@mergify
Copy link
Copy Markdown

mergify Bot commented Feb 25, 2026

@marlon-costa-dc Please associate the related issue to the body of your Pull Request. (eg. “issue: #187”)

Comment thread src/schema.rs
schema::FieldSchema {
field_id: 0,
name: fld.name.into(),
name: fld.name.clone(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fld.name.clone() performs a needless heap allocation. fld is an owned parameter consumed by this From impl, and name is only used here — it can be moved directly. This also contradicts the PR's stated goal of idiomatic Rust patterns, and is inconsistent with line 415 where description: fld.description already uses a direct move.

Comment thread src/data.rs
@@ -1,4 +1,5 @@
use std::borrow::Cow;
use std::convert::TryFrom;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The project uses edition = "2021" (Cargo.toml), which includes TryFrom in the prelude. This import is unnecessary — src/schema.rs in the same PR uses try_from without it. The same redundant import also appears at src/types.rs:1. In a PR that aims to clean up clippy warnings, adding superfluous imports is counterproductive.

@yhmo yhmo force-pushed the refactor/clippy-and-idiomatic-fixes branch from 9e298dc to 2b89375 Compare April 30, 2026 10:20
@mergify mergify Bot added the ci-passed label Apr 30, 2026
@yhmo yhmo force-pushed the refactor/clippy-and-idiomatic-fixes branch from 2b89375 to 89c03e1 Compare May 6, 2026 04:05
Copilot AI review requested due to automatic review settings May 6, 2026 04:05
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR focuses on addressing clippy warnings and making several small refactors to align the SDK with more idiomatic Rust patterns (e.g., matches!, field init shorthand, and derived Default).

Changes:

  • Refactors a number of boolean / match-based checks to use matches!() and other idiomatic patterns.
  • Replaces several manual Default impls with #[derive(Default)], and simplifies struct initializations.
  • Adjusts protobuf enum decoding to use DataType::try_from(...) and adds an is_empty() convenience method on FieldColumn.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/value.rs Refactors check_dtype to use matches!() instead of a match with boolean returns.
src/types.rs Switches enum decoding to DataType::try_from(...) (with a new import added).
src/schema.rs Uses try_from for enum decoding; simplifies validate; tweaks schema conversions and builder logic.
src/partition.rs Derives Default for options; simplifies request construction using ..Default::default().
src/options.rs Replaces manual Default impl with #[derive(Default)] for options.
src/mutate.rs Derives Default for insert options; minor string-building tweaks in delete expression composition.
src/index/mod.rs Uses field init shorthand in From<IndexDescription> for IndexInfo.
src/database.rs Replaces manual Default impl with #[derive(Default)] for database options.
src/data.rs Switches enum decoding to try_from; adds FieldColumn::is_empty().
src/client.rs Minor string formatting simplification (format! -> to_string).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/schema.rs
fields: this.inner,
name: this.name,
description: this.description,
enable_dynamic_field: self.enable_dynamic_field,
Comment thread src/schema.rs
Comment on lines 411 to 415
schema::FieldSchema {
field_id: 0,
name: fld.name.into(),
name: fld.name.clone(),
is_primary_key: fld.is_primary,
description: fld.description,
Comment thread src/data.rs
Comment on lines 136 to +141
self.value.len() / self.dim as usize
}

#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
Comment thread src/data.rs
@@ -1,4 +1,5 @@
use std::borrow::Cow;
use std::convert::TryFrom;
Comment thread src/types.rs
Comment on lines +1 to +2
use std::convert::TryFrom;

Comment thread src/mutate.rs
Comment on lines 164 to 168
if i > 0 {
expr.push_str(",");
expr.push(',');
}
expr.push_str(v.as_str());
}
Comment thread src/mutate.rs
Comment on lines 151 to 157
(DataType::Int64, ValueVec::Long(values)) => {
for (i, v) in values.iter().enumerate() {
if i > 0 {
expr.push_str(",");
expr.push(',');
}
expr.push_str(format!("{}", v).as_str());
}
@yhmo yhmo added the code-conflict Code conflict, cannot be merged label May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants