Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
docs: Improve AsRef / AsMut docs on blanket impls #99460
docs: Improve AsRef / AsMut docs on blanket impls #99460
Changes from 3 commits
551d921
9f68e3e
e4a259b
e6b761b
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
It is unclear to me whether this monomorphize optimization is helpful to portray the meaning of the example.
(e.g. remove the
doit
function, and mention the possible optimization in words below the example instead, with a relevant link. That is, if that "tip" merits staying on thisAsMut
doc page.)I haven't read over very much of
std
doc, so it is possible things like this "tip not strictly related, but useful" are more common than I realize.Just wanted to draw attention for consideration / discussion.
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.
Providing a generic API is the use case of
AsRef
. Unfortunately, the compiler isn't capable of doing these optimizations by itself. I think people who write generic APIs should see how it's done correctly (with current Rust).I agree, however, that it makes the example even more complex. Maybe the example code could be non-optimized and the "better practice" added at the end:
What do you think about it, and do you know how (and with what target?) I could (should?) link "monomorphization" in the docs properly?
Downside would be it makes the example section even longer, but maybe it's necessary to not confuse readers.
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 now see what you mean, generic usage is pretty central to these types.
The only reference I could find comes from a rust perf book, which is a separate project, not part of the official rust documentation. I don't think this should be linked in
std
docs.I like having this optimization separated out. When the compiler is improved in the future to optimize this for users, then this addendum could be easily removed.
I'd like to hear what more seasoned rust members think, for the question of whether to include the optimization example now.
As that link mentions,
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 generally would feel okay with keeping it as it is, but I also would like to hear some other opinions, as I acknowledge this makes the whole example a bit long. I don't see a good reference to link to (and none that is part of
std
orrust
itself) – at least I didn't find any.