As you have already been made awareyou have already been made aware, you should not be using
&mut Vec<T>unless you plan on adding or removing items from theVec. Using&mut [T]better expresses the contract of the function and is more flexible, allowing you to also sort arrays and anything else that can be expressed as a slice.whereclauses go on a separate line. This allows them to be easily found, which is important considering how much they affect the behavior of the function.There's no need to declare the type of
pos. Type inference will take care of it.There's no need to redeclare
posjust to make it mutable and decrement it. Just make the variable binding in the function declarationmut.There's no need to return the unit value (
()). Justreturnwill suffice.slice::swapexists. In the broader world, so doesmem::swap.With the power of
swap, you can remove the need for theCopybound.Quickcheck is an invaluable tool for problems like this. You can create a property that can be validated across a wide range of automatically generated input.
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/