r/rust•
micachito

sort reverse not working

Hi

​

I have a vector of structs and would like to sort it in asc or desc order.

What I am doing is this:

define a struct

​

pub struct CustomerAccountMovement {
    pub id: i32,
    pub movement_date: String,
    pub amount: f32,
    pub concept: String,
    pub customer_account_id: i32,
}

​

define a vector with such struct

​

let mut v: Vec<CustomerAccountMovement>

And when it is populated I am trying to perform the sort:

​

// Get parameter sort
 if msg.asc == 0 {
            v.sort_by_key(|x| (x.id, Reverse(x.id))); 
        } else {
            v.sort_by_key(|x| x.id); 
        }

​

I have tried a couple of times and data is always in the same order...

Am I doing something wrong?

​

Thanks in advance

J

Posted May 7, 2019, 11:02 AM UTC

110
Loading comments…