-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.P-mediumMedium priorityMedium priority
Description
The recently introduced slice method swap_with_slice() can't be used to swap two nonoverlapping parts of a single slice. But when you reshuffle parts of a single slice I think it could be useful. So I suggest to offer a slice function that performs this operation safely:
v.swap_nonoverlapping(i, j, n);
That's just a wrapper around (plus panics):
use std::ptr::swap_nonoverlapping;
swap_nonoverlapping(v[i ..].as_mut_ptr(), v[j ..].as_mut_ptr(), n);
Metadata
Metadata
Assignees
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.P-mediumMedium priorityMedium priority
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
Thiez commentedon Oct 30, 2017
Sure it can be:
leonardo-m commentedon Oct 30, 2017
Nice solution... so do you suggest me to close down this enhancement request?
Thiez commentedon Oct 30, 2017
I am not part of the official Rust project, so I have no authority to tell you to do anything 😄. If you think the code I've shown is good enough that you feel your proposed enhancement is no longer relevant, then sure, close the issue. But if you still think a
swap_nonoverlapping
method would be a good idea, then by all means continue. However, the usual way of getting additions to the standard library is to go through the RFC process. Be warned, it's quite a lot of work.leonardo-m commentedon Oct 30, 2017
I think your solution is good enough for my problem. But I think eventually we'll need a solution for the discoverability of similar solutions combining two or three functions of the std library ::-) It's a matter of documentation... So I keep this issue open, but I suggest the addition of your solution to the docs of swap_with_slice().
scottmcm commentedon Oct 30, 2017
It would be great to get a doc PR for all of
copy_from_slice
,clone_from_slice
, andswap_with_slice
that demonstrate using range indexing andsplit_at
to work with sub-slices. A few people have shown up on IRC asking about that after getting panics for different lengths and not knowing what to do.[-]slice swap_nonoverlapping[/-][+]Example in docs of swap_with_slice()[/+]Improve documentation for slice swap/copy/clone operations.
frewsxcv commentedon Nov 23, 2017
Opened a PR for this: #46219
Improve documentation for slice swap/copy/clone operations.
Rollup merge of rust-lang#46219 - rust-lang:frewsxcv-issue-45636, r=G…