-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
replace unnecessary owned-type to borrowed-type (String) #525
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
|
I've encountered some compilation errors related to the incorrect implementation of Here are the details: error: incorrect implementation of `partial_cmp` on an `Ord` type
--> src/general/huffman_encoding.rs:29:1
|
29 | / impl<T> PartialOrd for HuffmanNode<T> {
30 | | fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
| | _____________________________________________________________-
31 | || Some(self.frequency.cmp(&other.frequency).reverse())
32 | || }
| ||_____- help: change this to: `{ Some(self.cmp(other)) }`
33 | | }
| |__^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incorrect_partial_ord_impl_on_ord_type
= note: `#[deny(clippy::incorrect_partial_ord_impl_on_ord_type)]` on by default
error: incorrect implementation of `partial_cmp` on an `Ord` type
--> src/graph/astar.rs:17:1
|
17 | / impl<V: Ord + Copy, E: Ord + Copy> PartialOrd for Candidate<V, E> {
18 | | fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
| | _______________________________________________________________________-
19 | || // Note the inverted order; we want nodes with lesser weight to have
20 | || // higher priority
21 | || other.estimated_weight.partial_cmp(&self.estimated_weight)
22 | || }
| ||_____- help: change this to: `{ Some(self.cmp(other)) }`
23 | | }
| |__^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incorrect_partial_ord_impl_on_ord_type
error: could not compile `the_algorithms_rust` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error: could not compile `the_algorithms_rust` (lib test) due to 2 previous errors Should I add a "#[allow(...)]" option since the code was written intentionally, or make new method? We'd appreciate it if you could take a look at these issues within the context of the existing Pull Request conversation and provide your feedback. If you have any suggestions or concerns, please let us know. |
Can't we replace partial_cmp implementation with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
Pull Request
Description
This pull request aims to improve code quality and memory efficiency by promoting the use of borrowed references (
&str
) over unnecessary ownership (String
).Change function signatures (String -> &str)
Change the code in test (remove unnecessary String construction)
Type of change
Checklist:
cargo clippy --all -- -D warnings
just before my last commit and fixed any issue that was found.cargo fmt
just before my last commit.cargo test
just before my last commit and all tests passed.COUNTRIBUTING.md
and my code follows its guidelines.Question
I found some issues when I ran
cargo clippy --all -- -D warnings
.Those issues don't seem related to code I modified. What should I do?
Which type is better for code followed
(&str, usize)
,&[&str]
(it's not easy to make reference from(String, usize)
orVec<String>
)<T: AsRef<str>>(T, usize)
,<T: AsRef<str>>&[T]
Rust/src/string/autocomplete_using_trie.rs
Line 79 in e6be8cc
Rust/src/string/burrows_wheeler_transform.rs
Line 22 in e6be8cc
This marks my first-ever contribution, and I would greatly appreciate any guidance or feedback on areas where I may have made mistakes or could improve.