human
Could you please write me Rust code that takes ownership of an array of integers and sorts them in ascending order?
gpt
Sure, here's an implementation in Rust:

```
fn sort_ascending(arr: &mut [i32]) {
    arr.sort_unstable();
}

fn main() {
    let mut arr = [5, 2, 4, 1, 3];
    sort_ascending(&mut arr);
    println!("{:?}", arr);
}
```

This code sorts the array arr in place using the sort_unstable method. The sort_unstable method sorts the slice in place and may not preserve the order of equal elements.
human
do it in descending order
gpt
Sure! To sort an array of integers in descending order, you can create a sort_descending function like this:

```
fn sort_descending(arr: &mut [i32]) {
    arr.sort_unstable_by(|a, b| b.cmp(a));
}

fn main() {
    let mut arr = [5, 2, 4, 1, 3];
    sort_descending(&mut arr);
    println!("{:?}", arr);
}
```

Here, the `sort_unstable_by` method is used with a comparison closure that reverses the ordering of elements. The `cmp` method returns an ordering value that represents the relative order of two elements. Reversing the order of the arguments to `cmp` will cause it to return a value that represents the opposite ordering, which is what we need for a descending sort.