From 321e3c490906fed6ed1d46a7cbd2d2f9a42c9a53 Mon Sep 17 00:00:00 2001 From: Zack Corr Date: Sat, 19 Jan 2013 19:58:24 +1000 Subject: [PATCH] Add cmp::Ord implementation for semver::Version --- src/libcore/semver.rs | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/libcore/semver.rs b/src/libcore/semver.rs index 5a739772d1e..fc5d951edc5 100644 --- a/src/libcore/semver.rs +++ b/src/libcore/semver.rs @@ -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;