3636#![ doc( html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png" ,
3737 html_favicon_url = "http://www.rust-lang.org/favicon.ico" ,
3838 html_root_url = "http://doc.rust-lang.org/0.11.0/" ) ]
39+ #![ feature( default_type_params) ]
3940
4041use std:: char;
4142use std:: cmp;
42- use std:: fmt;
4343use std:: fmt:: Show ;
44- use std:: option :: { Option , Some , None } ;
45- use std:: string :: String ;
44+ use std:: fmt ;
45+ use std:: hash ;
4646
4747/// An identifier in the pre-release or build metadata. If the identifier can
4848/// be parsed as a decimal value, it will be represented with `Numeric`.
49- #[ deriving( Clone , PartialEq ) ]
49+ #[ deriving( Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
5050#[ allow( missing_doc) ]
5151pub enum Identifier {
5252 Numeric ( uint ) ,
5353 AlphaNumeric ( String )
5454}
5555
56- impl cmp:: PartialOrd for Identifier {
57- #[ inline]
58- fn partial_cmp ( & self , other : & Identifier ) -> Option < Ordering > {
59- match ( self , other) {
60- ( & Numeric ( a) , & Numeric ( ref b) ) => a. partial_cmp ( b) ,
61- ( & Numeric ( _) , _) => Some ( Less ) ,
62- ( & AlphaNumeric ( ref a) , & AlphaNumeric ( ref b) ) => a. partial_cmp ( b) ,
63- ( & AlphaNumeric ( _) , _) => Some ( Greater )
64- }
65- }
66- }
67-
6856impl fmt:: Show for Identifier {
6957 #[ inline]
7058 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
@@ -77,7 +65,7 @@ impl fmt::Show for Identifier {
7765
7866
7967/// Represents a version number conforming to the semantic versioning scheme.
80- #[ deriving( Clone ) ]
68+ #[ deriving( Clone , Eq ) ]
8169pub struct Version {
8270 /// The major version, to be incremented on incompatible changes.
8371 pub major : uint ,
@@ -129,35 +117,49 @@ impl cmp::PartialEq for Version {
129117}
130118
131119impl cmp:: PartialOrd for Version {
132- #[ inline]
133120 fn partial_cmp ( & self , other : & Version ) -> Option < Ordering > {
134- match self . major . partial_cmp ( & other. major ) {
135- Some ( Equal ) => { }
121+ Some ( self . cmp ( other) )
122+ }
123+ }
124+
125+ impl cmp:: Ord for Version {
126+ fn cmp ( & self , other : & Version ) -> Ordering {
127+ match self . major . cmp ( & other. major ) {
128+ Equal => { }
136129 r => return r,
137130 }
138131
139- match self . minor . partial_cmp ( & other. minor ) {
140- Some ( Equal ) => { }
132+ match self . minor . cmp ( & other. minor ) {
133+ Equal => { }
141134 r => return r,
142135 }
143136
144- match self . patch . partial_cmp ( & other. patch ) {
145- Some ( Equal ) => { }
137+ match self . patch . cmp ( & other. patch ) {
138+ Equal => { }
146139 r => return r,
147140 }
148141
149142 // NB: semver spec says 0.0.0-pre < 0.0.0
150143 // but the version of ord defined for vec
151144 // says that [] < [pre] so we alter it here
152145 match ( self . pre . len ( ) , other. pre . len ( ) ) {
153- ( 0 , 0 ) => Some ( Equal ) ,
154- ( 0 , _) => Some ( Greater ) ,
155- ( _, 0 ) => Some ( Less ) ,
156- ( _, _) => self . pre . partial_cmp ( & other. pre )
146+ ( 0 , 0 ) => Equal ,
147+ ( 0 , _) => Greater ,
148+ ( _, 0 ) => Less ,
149+ ( _, _) => self . pre . cmp ( & other. pre )
157150 }
158151 }
159152}
160153
154+ impl < S : hash:: Writer > hash:: Hash < S > for Version {
155+ fn hash ( & self , into : & mut S ) {
156+ self . major . hash ( into) ;
157+ self . minor . hash ( into) ;
158+ self . patch . hash ( into) ;
159+ self . pre . hash ( into) ;
160+ }
161+ }
162+
161163fn take_nonempty_prefix < T : Iterator < char > > ( rdr : & mut T , pred: |char| -> bool)
162164 -> ( String , Option < char > ) {
163165 let mut buf = String :: new ( ) ;
0 commit comments