Skip to content

Example in docs of swap_with_slice() #45636

Closed
@leonardo-m

Description

@leonardo-m

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 toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.P-mediumMedium priority

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions