]> git.proxmox.com Git - rustc.git/blob - src/doc/book/listings/ch13-functional-features/listing-13-08/src/main.rs
New upstream version 1.62.1+dfsg1
[rustc.git] / src / doc / book / listings / ch13-functional-features / listing-13-08 / src / main.rs
1 #[derive(Debug)]
2 struct Rectangle {
3 width: u32,
4 height: u32,
5 }
6
7 fn main() {
8 let mut list = [
9 Rectangle {
10 width: 10,
11 height: 1,
12 },
13 Rectangle {
14 width: 3,
15 height: 5,
16 },
17 Rectangle {
18 width: 7,
19 height: 12,
20 },
21 ];
22
23 let mut sort_operations = vec![];
24 let value = String::from("by key called");
25
26 list.sort_by_key(|r| {
27 sort_operations.push(value);
28 r.width
29 });
30 println!("{:#?}", list);
31 }