#[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 sort_operations = vec![];
let value = String::from("by key called");
list.sort_by_key(|r| {
sort_operations.push(value); // 如果这里改成 sort_operations.push(value.clone());
// 那么这个闭包体就是 FnMut 类型了
r.width
});
println!("{:#?}", list);
}