mirror of
https://github.com/gnu4cn/rust-lang-zh_CN.git
synced 2026-08-22 22:23:28 +08:00
reorganized the directories
This commit is contained in:
22
projects/closure-example/src/main.rs
Normal file
22
projects/closure-example/src/main.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
#[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("按照被调用到的 key");
|
||||
|
||||
list.sort_by_key(|r| {
|
||||
sort_operations.push(&value);
|
||||
r.width
|
||||
});
|
||||
println! ("{:#?}\n{:#?}", list, sort_operations);
|
||||
}
|
||||
Reference in New Issue
Block a user