Logo

Programming-Idioms

History of Idiom 28 > diff from v64 to v65

Edit summary for version 65 by programming-idioms.org:
[Rust] +DemoURL, +DocURL

Version 64

2021-02-26, 20:09:50

Version 65

2021-03-24, 20:32:58

Idiom #28 Sort by a property

Sort elements of array-like collection items in ascending order of x.p, where p is a field of the type Item of the objects in items.

Idiom #28 Sort by a property

Sort elements of array-like collection items in ascending order of x.p, where p is a field of the type Item of the objects in items.

Variables
items,x,p
Variables
items,x,p
Code
items.sort_by(|a,b|a.p.cmp(&b.p));
Code
items.sort_by(|a,b|a.p.cmp(&b.p));
Doc URL
https://doc.rust-lang.org/std/primitive.slice.html#method.sort_by
Demo URL
https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=f40b0b2385f565d377c7b3bb91cc9314