Commit 7c9ac4f
authored
Rollup merge of #38995 - petrochenkov:minmax, r=GuillaumeGomez
Fix docs for min/max algorithms
I thought at first "what did they think about when stabilizing this!?", but it turned out it's just wrong docs. Phew.
r? @steveklabnik
Test:
```
use std::cmp::Ordering;
struct S(u8, u8);
impl PartialEq for S {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl PartialOrd for S {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.0.cmp(&other.0))
}
}
impl Ord for S {
fn cmp(&self, other: &Self) -> Ordering {
self.0.cmp(&other.0)
}
}
fn main() {
let arr = [S(0, 1), S(0, 2)];
println!("min {:?}", arr.iter().min());
println!("min_by {:?}", arr.iter().min_by(|x, y| x.0.cmp(&y.0)));
println!("min_by_key {:?}", arr.iter().min_by_key(|x| x.0));
println!("max {:?}", arr.iter().max());
println!("max_by {:?}", arr.iter().max_by(|x, y| x.0.cmp(&y.0)));
println!("max_by_key {:?}", arr.iter().max_by_key(|x| x.0));
}
```
Output:
```
rustc 1.15.0-beta.3 (a035041 2017-01-07)
min Some(S(0, 1))
min_by Some(S(0, 1))
min_by_key Some(S(0, 1))
max Some(S(0, 2))
max_by Some(S(0, 2))
max_by_key Some(S(0, 2))
```1 file changed
+10
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1612 | 1612 | | |
1613 | 1613 | | |
1614 | 1614 | | |
1615 | | - | |
| 1615 | + | |
1616 | 1616 | | |
1617 | 1617 | | |
1618 | 1618 | | |
| |||
1638 | 1638 | | |
1639 | 1639 | | |
1640 | 1640 | | |
1641 | | - | |
| 1641 | + | |
1642 | 1642 | | |
1643 | 1643 | | |
1644 | 1644 | | |
| |||
1665 | 1665 | | |
1666 | 1666 | | |
1667 | 1667 | | |
1668 | | - | |
1669 | | - | |
| 1668 | + | |
| 1669 | + | |
1670 | 1670 | | |
1671 | 1671 | | |
1672 | 1672 | | |
| |||
1690 | 1690 | | |
1691 | 1691 | | |
1692 | 1692 | | |
1693 | | - | |
1694 | | - | |
| 1693 | + | |
| 1694 | + | |
1695 | 1695 | | |
1696 | 1696 | | |
1697 | 1697 | | |
| |||
1715 | 1715 | | |
1716 | 1716 | | |
1717 | 1717 | | |
1718 | | - | |
1719 | | - | |
| 1718 | + | |
| 1719 | + | |
1720 | 1720 | | |
1721 | 1721 | | |
1722 | 1722 | | |
| |||
1739 | 1739 | | |
1740 | 1740 | | |
1741 | 1741 | | |
1742 | | - | |
1743 | | - | |
| 1742 | + | |
| 1743 | + | |
1744 | 1744 | | |
1745 | 1745 | | |
1746 | 1746 | | |
| |||
0 commit comments