Pass function closure to thread

First, please format the code in your post according to the pinned post, it makes it easier to read.

Second, the issue there seems to be that get_statistic() takes stat by value, and Statistic does not implement Copy. That means each call to get_statistic() moves stat into the function, so the closure key_fn can only be called once, so it only implements FnOnce. However, Vec::sort_by_key() takes something that implements FnMut, since it calls it repeatedly.

There are two options for solutions. One would be to add #[derive(Copy)] to the Statistic enum, since it is a very small and simple type. The other option, if Statistic couldn't be made Copy for some reason, would be to modify get_statistic() to take a reference to stat instead.

That code also seems to have the problem that it is using Vec without specifying its generic parameter. The signature of start_sorting_thread() should be:

fn start_sorting_thread(
    mut cities: Vec<City>,
    stat: Statistic,
) -> thread::JoinHandle<Vec<City>> {