Skip to content
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

[Rust] No need to use mut iter #1356

Merged
merged 2 commits into from May 12, 2024
Merged

[Rust] No need to use mut iter #1356

merged 2 commits into from May 12, 2024

Conversation

rongyi
Copy link
Contributor

@rongyi rongyi commented May 10, 2024

there's no need to use mut iter, just iter is enough

@rongyi rongyi changed the title No need to use mut iter [Rust] No need to use mut iter May 10, 2024
@@ -31,16 +31,16 @@ fn counting_sort_naive(nums: &mut [i32]) {
// 完整实现,可排序对象,并且是稳定排序
fn counting_sort(nums: &mut [i32]) {
// 1. 统计数组最大元素 m
let m = *nums.into_iter().max().unwrap();
let m = *nums.iter().max().unwrap() as usize;
Copy link
Owner

Choose a reason for hiding this comment

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

Why as usize?

Copy link
Contributor Author

@rongyi rongyi May 12, 2024

Choose a reason for hiding this comment

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

as you can see in the context, m is itended to be used as usize, in here we cast it to usize instead of multiple cast in used place.

Copy link
Owner

@krahets krahets left a comment

Choose a reason for hiding this comment

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

LGTM

@krahets krahets merged commit 063a41f into krahets:main May 12, 2024
4 checks passed
@krahets krahets added code Code-related embellishment Decorative detail or feature labels May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code Code-related embellishment Decorative detail or feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants