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

Improve hint for as_ref_mut #1113

Merged
merged 1 commit into from
Jun 12, 2023
Merged
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
2 changes: 1 addition & 1 deletion info.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1135,4 +1135,4 @@ name = "as_ref_mut"
path = "exercises/conversions/as_ref_mut.rs"
mode = "test"
hint = """
Add AsRef<str> as a trait bound to the functions."""
Add AsRef<str> or AsMut<u32> as a trait bound to the functions."""
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Add AsRef<str> or AsMut<u32> as a trait bound to the functions."""
Add AsRef<str> or AsMut<u32> as a trait bound to the functions as appropriate."""

Copy link

@CaliViking CaliViking Aug 7, 2022

Choose a reason for hiding this comment

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

Why would you limit the trait to u32? Shouldn't the trait allow any parameter that can be squared, so Mul trait? I know that the unit test specifies u32, but that seems pretty narrow, shouldn't the function support i32, i64, u32, u64, f32, f64?

Copy link
Member

Choose a reason for hiding this comment

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

It's just as an example 🤷

Copy link

@godmir godmir Apr 3, 2023

Choose a reason for hiding this comment

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

You can actually make it generic, e.g.:

fn num_sq<T: AsMut<U> + AsRef<U>, U>(arg: &mut T) where U: Copy + MulAssign<U> {
    let x = *arg.as_ref();
    *arg.as_mut() *= x;
}