Make Vec::split_at_spare_mut public#81687
Merged
bors merged 4 commits intorust-lang:masterfrom Feb 10, 2021
Merged
Conversation
This commit introduces a new method to the public API, under
`vec_split_at_spare` feature gate:
```rust
impl<T, A: Allocator> impl Vec<T, A> {
pub fn split_at_spare_mut(&mut self) -> (&mut [T], &mut [MaybeUninit<T>]);
}
```
The method returns 2 slices, one slice references the content of the vector,
and the other references the remaining spare capacity.
The method was previously implemented while adding `Vec::extend_from_within`,
and used to implement `Vec::spare_capacity_mut` (as the later is just a
subset of former one).
Contributor
|
Thanks @WaffleLapkin! It might be worth noting that this is a low-level API, and if all you want to do is append data to a |
the8472
reviewed
Feb 3, 2021
Co-authored-by: the8472 <the8472@users.noreply.github.com>
Member
Author
|
ping @KodrAus I've addressed your comment. |
5 tasks
KodrAus
reviewed
Feb 9, 2021
Contributor
|
@bors r+ rollup |
Collaborator
|
📌 Commit 8ff7b75 has been approved by |
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Feb 10, 2021
Rollup of 11 pull requests Successful merges: - rust-lang#79849 (Clarify docs regarding sleep of zero duration) - rust-lang#80438 (Add `Box::into_inner`.) - rust-lang#81466 (Add suggest mut method for loop) - rust-lang#81687 (Make Vec::split_at_spare_mut public) - rust-lang#81904 (Bump stabilization version for const int methods) - rust-lang#81909 ([compiler/rustc_typeck/src/check/expr.rs] Remove unnecessary refs in pattern matching) - rust-lang#81910 (Use format string in bootstrap panic instead of a string directly) - rust-lang#81913 (Rename HIR UnOp variants) - rust-lang#81925 (Add long explanation for E0547) - rust-lang#81926 (add suggestion to use the `async_recursion` crate) - rust-lang#81951 (Update cargo) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Contributor
|
🚲 I think this can replace It would be good if the function had Vec has |
Member
Author
|
Yeah, I agree that it would be better to just have one method for getting spare capacity. Though I'm not sure how to discuss this replacement properly... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR introduces a new method to the public API, under
vec_split_at_sparefeature gate:The method returns 2 slices, one slice references the content of the vector,
and the other references the remaining spare capacity.
The method was previously implemented while adding
Vec::extend_from_withinin #79015,and used to implement
Vec::spare_capacity_mut(as the later is just asubset of former one).
See also previous discussion in
Vec::spare_capacity_muttracking issue.Unresolved questions
split_at_spare_mutdoesn't seem like an intuitive nameVec::spare_capacity_mut? Any usecase ofVec::spare_capacity_mutcan be replaced withVec::split_at_spare_mut(but not vise-versa)r? @KodrAus