Add cmp::Ord implementation for semver::Version
This commit is contained in:
parent
f18ae8ce7e
commit
321e3c4909
@ -17,6 +17,7 @@ use uint;
|
||||
use str;
|
||||
use to_str::ToStr;
|
||||
use char;
|
||||
use cmp;
|
||||
|
||||
pub struct Version {
|
||||
major: uint,
|
||||
@ -37,6 +38,61 @@ impl Version: ToStr {
|
||||
}
|
||||
}
|
||||
|
||||
impl Version: cmp::Ord {
|
||||
#[inline(always)]
|
||||
pure fn lt(&self, other: &Version) -> bool {
|
||||
self.major < other.major ||
|
||||
self.minor < other.minor ||
|
||||
self.patch < other.patch ||
|
||||
(match self.tag {
|
||||
Some(stag) => match other.tag {
|
||||
Some(otag) => stag < otag,
|
||||
None => true
|
||||
},
|
||||
None => false
|
||||
})
|
||||
}
|
||||
#[inline(always)]
|
||||
pure fn le(&self, other: &Version) -> bool {
|
||||
self.major <= other.major ||
|
||||
self.minor <= other.minor ||
|
||||
self.patch <= other.patch ||
|
||||
(match self.tag {
|
||||
Some(stag) => match other.tag {
|
||||
Some(otag) => stag <= otag,
|
||||
None => true
|
||||
},
|
||||
None => false
|
||||
})
|
||||
}
|
||||
#[inline(always)]
|
||||
pure fn gt(&self, other: &Version) -> bool {
|
||||
self.major > other.major ||
|
||||
self.minor > other.minor ||
|
||||
self.patch > other.patch ||
|
||||
(match self.tag {
|
||||
Some(stag) => match other.tag {
|
||||
Some(otag) => stag > otag,
|
||||
None => false
|
||||
},
|
||||
None => true
|
||||
})
|
||||
}
|
||||
#[inline(always)]
|
||||
pure fn ge(&self, other: &Version) -> bool {
|
||||
self.major >= other.major ||
|
||||
self.minor >= other.minor ||
|
||||
self.patch >= other.patch ||
|
||||
(match self.tag {
|
||||
Some(stag) => match other.tag {
|
||||
Some(otag) => stag >= otag,
|
||||
None => false
|
||||
},
|
||||
None => true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn read_whitespace(rdr: io::Reader, ch: char) -> char {
|
||||
let mut nch = ch;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user