Skip to content

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

Merged
merged 1 commit into from
Jan 16, 2015
Merged

Conversation

steveklabnik
Copy link
Member

Fixes #17224

@rust-highfive
Copy link
Contributor

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> {
Copy link
Member

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

Copy link
Member Author

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...

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Contributor

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.

Copy link
Member

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.

bors added a commit that referenced this pull request Jan 14, 2015
Provide example of generic inverse()

Reviewed-by: alexcrichton
bors added a commit that referenced this pull request Jan 14, 2015
Provide example of generic inverse()

Reviewed-by: alexcrichton
bors added a commit that referenced this pull request Jan 15, 2015
Provide example of generic inverse()

Reviewed-by: alexcrichton
bors added a commit that referenced this pull request Jan 15, 2015
Provide example of generic inverse()

Reviewed-by: alexcrichton
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Jan 15, 2015
@bors bors merged commit ad0ce88 into rust-lang:master Jan 16, 2015
@steveklabnik steveklabnik deleted the gh17224 branch October 25, 2017 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Guide: Fixing Inverse in Generics section
6 participants