-
Notifications
You must be signed in to change notification settings - Fork 13.6k
docs: Mention spare_capacity_mut()
in Vec::set_len
#126118
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
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @m-ou-se (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
This comment has been minimized.
This comment has been minimized.
library/alloc/src/vec/mod.rs
Outdated
/// unsafe { | ||
/// vec.set_len(256); | ||
/// } | ||
/// ``` |
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 might even be worth it to move this above the FFI example since this use usable with pure rust.
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.
Happy to amend the commit accordingly. Who'd be an authority for such decisions?
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.
Who'd be an authority for such decisions?
Whoever says something that makes the most sense, which could be you :) docs changes are usually EAFP. (agreed that it makes sense to move this up).
library/alloc/src/vec/mod.rs
Outdated
/// unsafe { | ||
/// vec.set_len(256); | ||
/// } |
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.
Minor style:
/// unsafe { | |
/// vec.set_len(256); | |
/// } | |
/// unsafe { vec.set_len(256) }; |
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.
Though I'd also write it like you suggest, I've based this on the existing examples for the same method and opted for consistency.
Maybe it's best to just link to the documentation+example of spare_capacity_mut? Or to re-use the example from that method's documentation? |
I feel queasy about copy-pasting the example from |
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.
This minimal change looks fine to me, I think we should be able to merge this unless @the8472 you have other suggestions.
@bors r+ |
I recently went down a small rabbit hole when trying to identify safe use of
Vec::set_len
. The solution wasVec::spare_capacity_mut
. I think the docs onVec::set_len
benefit from mentioning this method.A possible counter-argument could be that the clippy lint
uninit_vec
already nudges people in the right direction. However, I think a working example onVec::set_len
is still beneficial.Happy to hear your thoughts on the matter. 😊