Skip to content

Commit ce49c24

Browse files
Update for RFC#28: Add PartialOrd::partial_cmp
See rust-lang/rust#15030
1 parent d3079a1 commit ce49c24

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

pkg.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::option::{Option};
2020
use std::os;
2121
use std::str;
2222

23-
#[deriving(PartialEq)]
23+
#[deriving(Eq, PartialEq)]
2424
struct Version {
2525
major: uint,
2626
minor: uint
@@ -43,8 +43,14 @@ impl std::fmt::Show for Version {
4343
}
4444

4545
impl PartialOrd for Version {
46-
fn lt(&self, other: &Version) -> bool {
47-
self.major < other.major || (self.major == other.major && self.minor < other.minor)
46+
fn partial_cmp(&self, other: &Version) -> Option<Ordering> {
47+
Some(self.cmp(other))
48+
}
49+
}
50+
51+
impl Ord for Version {
52+
fn cmp(&self, other: &Version) -> Ordering {
53+
(self.major, self.minor).cmp(&(other.major, other.minor))
4854
}
4955
}
5056

0 commit comments

Comments
 (0)