Skip to content

Commit 321e3c4

Browse files
z0w0graydon
authored andcommitted
Add cmp::Ord implementation for semver::Version
1 parent f18ae8c commit 321e3c4

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/libcore/semver.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use uint;
1717
use str;
1818
use to_str::ToStr;
1919
use char;
20+
use cmp;
2021

2122
pub struct Version {
2223
major: uint,
@@ -37,6 +38,61 @@ impl Version: ToStr {
3738
}
3839
}
3940

41+
impl Version: cmp::Ord {
42+
#[inline(always)]
43+
pure fn lt(&self, other: &Version) -> bool {
44+
self.major < other.major ||
45+
self.minor < other.minor ||
46+
self.patch < other.patch ||
47+
(match self.tag {
48+
Some(stag) => match other.tag {
49+
Some(otag) => stag < otag,
50+
None => true
51+
},
52+
None => false
53+
})
54+
}
55+
#[inline(always)]
56+
pure fn le(&self, other: &Version) -> bool {
57+
self.major <= other.major ||
58+
self.minor <= other.minor ||
59+
self.patch <= other.patch ||
60+
(match self.tag {
61+
Some(stag) => match other.tag {
62+
Some(otag) => stag <= otag,
63+
None => true
64+
},
65+
None => false
66+
})
67+
}
68+
#[inline(always)]
69+
pure fn gt(&self, other: &Version) -> bool {
70+
self.major > other.major ||
71+
self.minor > other.minor ||
72+
self.patch > other.patch ||
73+
(match self.tag {
74+
Some(stag) => match other.tag {
75+
Some(otag) => stag > otag,
76+
None => false
77+
},
78+
None => true
79+
})
80+
}
81+
#[inline(always)]
82+
pure fn ge(&self, other: &Version) -> bool {
83+
self.major >= other.major ||
84+
self.minor >= other.minor ||
85+
self.patch >= other.patch ||
86+
(match self.tag {
87+
Some(stag) => match other.tag {
88+
Some(otag) => stag >= otag,
89+
None => false
90+
},
91+
None => true
92+
})
93+
}
94+
}
95+
4096
fn read_whitespace(rdr: io::Reader, ch: char) -> char {
4197
let mut nch = ch;
4298

0 commit comments

Comments
 (0)