Replacement for std::slice::Permutations?


I need to generate all the possible permutations of a vector, but it looks like the relevant iterator in Rust (std::slice::Permutations) has been deprecated since version 1.2.0. Is there an appropriate replacement I should use?

I could probably write the function myself, but it seems like this should be part of the standard library (similar to versions in C++ and Python).


There’s a replacement in crate permutohedron. It contains various ways to access permutations in an efficient “arbitrary order” sequence (Heap’s algorithm) and also the lexical permutation steppers previously in libcore. Permutohedron’s variants should be much more efficient than the old Permutations iterator, especially since you can use it in in-place/streaming fashion.


Thanks! That’s exactly what I was looking for.

I’m not sure it belongs in the documentation, but a forwarding reference for deprecated or removed features would be nice. Rust has been changing fast enough that many tutorials still point to outdated doc pages.


We do try to do that in general but it unfortunately does not always happen, particularly when the replacement doesn’t already exist (or we’re not aware of it) when we’re making the deprecation message.

I believe we’d be happy to accept PRs adding references in places we’ve missed, though!