mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2025-05-07 14:30:19 +08:00
21 lines
441 B
Rust
Executable File
21 lines
441 B
Rust
Executable File
#[derive(Debug)]
|
|
struct Rectangle {
|
|
width: u32,
|
|
height: u32,
|
|
}
|
|
|
|
fn main() {
|
|
let mut list = [
|
|
Rectangle { width: 10, height: 1 },
|
|
Rectangle { width: 3, height: 5 },
|
|
Rectangle { width: 7, height: 12 },
|
|
];
|
|
|
|
let mut num_sort_operations = 0;
|
|
list.sort_by_key(|r| {
|
|
num_sort_operations += 1;
|
|
r.width
|
|
});
|
|
println!("{:#?}, sorted in {num_sort_operations} operations", list);
|
|
}
|