-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Provide example of generic inverse() #21109
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
Conversation
r? @brson (rust_highfive has picked a reviewer for you, use r? to override) |
this: | ||
|
||
```{rust,ignore} | ||
fn inverse<T: PartialEq>(x: T) -> Result<T, String> { |
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.
I think that we're conventionally recommending Eq
as a bound for generics rather than PartialEq
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.
Oh? But floats don't have Eq...
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.
Oh right! Perhaps integers could be used? Integers are the ones that panic on divide-by-zero as well.
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.
How big of a deal is it? I ask because this isn't just here, I'd have to go back and revise the other section. Which is fine, but maybe just mentioning how floats are a good example of the Eq
/ PartialEq
difference is worth it? Or maybe just show Eq and the different error message?
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.
I think keeping PartialEq
with the float is fine.
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.
Ah oh well, it's not worth that much trouble, PartialEq
is fine.
Provide example of generic inverse() Reviewed-by: alexcrichton
Provide example of generic inverse() Reviewed-by: alexcrichton
Provide example of generic inverse() Reviewed-by: alexcrichton
Provide example of generic inverse() Reviewed-by: alexcrichton
Fixes #17224