-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
What is a "perfect" conversion, for the From
trait?
#100376
Comments
It means infallible, like it should be a conversion that does not need to return a |
If it means infallible, then it's confusing that it says "If the conversion can fail or is not perfect", which makes it sound like "can fail" is different from "is not perfect". |
A couple heuristics that I use:
|
They are different intentionally, and the
and its example:
It also links back to
Here "perfect" means "without losing any information" in a very vague sense, or at least something along the lines of "every element in the source type has exactly one element in the target type and there is only one way to do this conversion". I think that the current wording in the docs isn't amazing, but I'm not sure how else to explain it (ideally without duplicating too much documentation between the traits, that will fall out of sync). |
Closing this as this was more a clarification issue than a bug or any enhancement. |
There's also now https://doc.rust-lang.org/stable/std/convert/trait.From.html#when-to-implement-from to elaborate on what this means, thanks to #114564 |
Location
This wording appears in the documentation for the
From
trait.Summary
The
From
trait has this note:It's not clear what "perfect" means here. Is there an established meaning for "perfect"? Does it mean lossless, and/or unambiguous? Or does it mean something else?
The text was updated successfully, but these errors were encountered: