I want to sort (reorder) a vector (inplace) by a predefined ordering in Rust.
For example
let i = vec![0, 3, 2, 1];
let mut v = vec!["a", "b", "c", "d"];
v.sort_by_indices(&i);
assert_eq!(v, &["a", "d", "c", "b"]);
I would like to do this inplace. In my use case, v takes up a lot of memory.
Note: this question is a natural follow-on from How to get the indices that would sort a vector in Rust?