3737//! assert!(SketchyNum {num: 25} != SketchyNum {num: 57});
3838//! ```
3939
40+ #![ stable]
41+
4042use option:: { Option , Some } ;
4143
4244/// Trait for values that can be compared for equality and inequality.
@@ -53,6 +55,7 @@ use option::{Option, Some};
5355/// Eventually, this will be implemented by default for types that implement
5456/// `Eq`.
5557#[ lang="eq" ]
58+ #[ unstable = "Definition may change slightly after trait reform" ]
5659pub trait PartialEq {
5760 /// This method tests for `self` and `other` values to be equal, and is used by `==`.
5861 fn eq ( & self , other : & Self ) -> bool ;
@@ -71,6 +74,7 @@ pub trait PartialEq {
7174/// - reflexive: `a == a`;
7275/// - symmetric: `a == b` implies `b == a`; and
7376/// - transitive: `a == b` and `b == c` implies `a == c`.
77+ #[ unstable = "Definition may change slightly after trait reform" ]
7478pub trait Eq : PartialEq {
7579 // FIXME #13101: this method is used solely by #[deriving] to
7680 // assert that every component of a type implements #[deriving]
@@ -86,6 +90,7 @@ pub trait Eq: PartialEq {
8690
8791/// An ordering is, e.g, a result of a comparison between two values.
8892#[ deriving( Clone , PartialEq , Show ) ]
93+ #[ stable]
8994pub enum Ordering {
9095 /// An ordering where a compared value is less [than another].
9196 Less = -1 i,
@@ -104,6 +109,7 @@ pub enum Ordering {
104109/// true; and
105110/// - transitive, `a < b` and `b < c` implies `a < c`. The same must hold for
106111/// both `==` and `>`.
112+ #[ unstable = "Definition may change slightly after trait reform" ]
107113pub trait Ord : Eq + PartialOrd {
108114 /// This method returns an ordering between `self` and `other` values.
109115 ///
@@ -118,15 +124,18 @@ pub trait Ord: Eq + PartialOrd {
118124 fn cmp ( & self , other : & Self ) -> Ordering ;
119125}
120126
127+ #[ unstable = "Trait is unstable." ]
121128impl Eq for Ordering { }
122129
130+ #[ unstable = "Trait is unstable." ]
123131impl Ord for Ordering {
124132 #[ inline]
125133 fn cmp ( & self , other : & Ordering ) -> Ordering {
126134 ( * self as int ) . cmp ( & ( * other as int ) )
127135 }
128136}
129137
138+ #[ unstable = "Trait is unstable." ]
130139impl PartialOrd for Ordering {
131140 #[ inline]
132141 fn partial_cmp ( & self , other : & Ordering ) -> Option < Ordering > {
@@ -140,6 +149,7 @@ impl PartialOrd for Ordering {
140149/// If the first ordering is different, the first ordering is all that must be returned.
141150/// If the first ordering is equal, then second ordering is returned.
142151#[ inline]
152+ #[ deprecated = "Just call .cmp() on an Ordering" ]
143153pub fn lexical_ordering ( o1 : Ordering , o2 : Ordering ) -> Ordering {
144154 match o1 {
145155 Equal => o2,
@@ -157,6 +167,7 @@ pub fn lexical_ordering(o1: Ordering, o2: Ordering) -> Ordering {
157167/// `NaN < 0 == false` and `NaN >= 0 == false` (cf. IEEE 754-2008 section
158168/// 5.11).
159169#[ lang="ord" ]
170+ #[ unstable = "Definition may change slightly after trait reform" ]
160171pub trait PartialOrd : PartialEq {
161172 /// This method returns an ordering between `self` and `other` values
162173 /// if one exists.
@@ -202,19 +213,22 @@ pub trait PartialOrd: PartialEq {
202213/// of different types. The most common use case for this relation is
203214/// container types; e.g. it is often desirable to be able to use `&str`
204215/// values to look up entries in a container with `String` keys.
216+ #[ experimental = "Better solutions may be discovered." ]
205217pub trait Equiv < T > {
206218 /// Implement this function to decide equivalent values.
207219 fn equiv ( & self , other : & T ) -> bool ;
208220}
209221
210222/// Compare and return the minimum of two values.
211223#[ inline]
224+ #[ stable]
212225pub fn min < T : Ord > ( v1 : T , v2 : T ) -> T {
213226 if v1 < v2 { v1 } else { v2 }
214227}
215228
216229/// Compare and return the maximum of two values.
217230#[ inline]
231+ #[ stable]
218232pub fn max < T : Ord > ( v1 : T , v2 : T ) -> T {
219233 if v1 > v2 { v1 } else { v2 }
220234}
@@ -227,6 +241,7 @@ mod impls {
227241
228242 macro_rules! eq_impl(
229243 ( $( $t: ty) * ) => ( $(
244+ #[ unstable = "Trait is unstable." ]
230245 impl PartialEq for $t {
231246 #[ inline]
232247 fn eq( & self , other: & $t) -> bool { ( * self ) == ( * other) }
@@ -236,6 +251,7 @@ mod impls {
236251 ) * )
237252 )
238253
254+ #[ unstable = "Trait is unstable." ]
239255 impl PartialEq for ( ) {
240256 #[ inline]
241257 fn eq ( & self , _other : & ( ) ) -> bool { true }
@@ -247,6 +263,7 @@ mod impls {
247263
248264 macro_rules! totaleq_impl(
249265 ( $( $t: ty) * ) => ( $(
266+ #[ unstable = "Trait is unstable." ]
250267 impl Eq for $t { }
251268 ) * )
252269 )
@@ -255,6 +272,7 @@ mod impls {
255272
256273 macro_rules! ord_impl(
257274 ( $( $t: ty) * ) => ( $(
275+ #[ unstable = "Trait is unstable." ]
258276 impl PartialOrd for $t {
259277 #[ inline]
260278 fn partial_cmp( & self , other: & $t) -> Option <Ordering > {
@@ -277,13 +295,15 @@ mod impls {
277295 ) * )
278296 )
279297
298+ #[ unstable = "Trait is unstable." ]
280299 impl PartialOrd for ( ) {
281300 #[ inline]
282301 fn partial_cmp ( & self , _: & ( ) ) -> Option < Ordering > {
283302 Some ( Equal )
284303 }
285304 }
286305
306+ #[ unstable = "Trait is unstable." ]
287307 impl PartialOrd for bool {
288308 #[ inline]
289309 fn partial_cmp ( & self , other : & bool ) -> Option < Ordering > {
@@ -295,6 +315,7 @@ mod impls {
295315
296316 macro_rules! totalord_impl(
297317 ( $( $t: ty) * ) => ( $(
318+ #[ unstable = "Trait is unstable." ]
298319 impl Ord for $t {
299320 #[ inline]
300321 fn cmp( & self , other: & $t) -> Ordering {
@@ -306,11 +327,13 @@ mod impls {
306327 ) * )
307328 )
308329
330+ #[ unstable = "Trait is unstable." ]
309331 impl Ord for ( ) {
310332 #[ inline]
311333 fn cmp ( & self , _other : & ( ) ) -> Ordering { Equal }
312334 }
313335
336+ #[ unstable = "Trait is unstable." ]
314337 impl Ord for bool {
315338 #[ inline]
316339 fn cmp ( & self , other : & bool ) -> Ordering {
@@ -321,12 +344,14 @@ mod impls {
321344 totalord_impl ! ( char uint u8 u16 u32 u64 int i8 i16 i32 i64 )
322345
323346 // & pointers
347+ #[ unstable = "Trait is unstable." ]
324348 impl < ' a , T : PartialEq > PartialEq for & ' a T {
325349 #[ inline]
326350 fn eq ( & self , other : & & ' a T ) -> bool { * ( * self ) == * ( * other) }
327351 #[ inline]
328352 fn ne ( & self , other : & & ' a T ) -> bool { * ( * self ) != * ( * other) }
329353 }
354+ #[ unstable = "Trait is unstable." ]
330355 impl < ' a , T : PartialOrd > PartialOrd for & ' a T {
331356 #[ inline]
332357 fn partial_cmp ( & self , other : & & ' a T ) -> Option < Ordering > {
@@ -341,19 +366,23 @@ mod impls {
341366 #[ inline]
342367 fn gt ( & self , other : & & ' a T ) -> bool { * ( * self ) > * ( * other) }
343368 }
369+ #[ unstable = "Trait is unstable." ]
344370 impl < ' a , T : Ord > Ord for & ' a T {
345371 #[ inline]
346372 fn cmp ( & self , other : & & ' a T ) -> Ordering { ( * * self ) . cmp ( * other) }
347373 }
374+ #[ unstable = "Trait is unstable." ]
348375 impl < ' a , T : Eq > Eq for & ' a T { }
349376
350377 // &mut pointers
378+ #[ unstable = "Trait is unstable." ]
351379 impl < ' a , T : PartialEq > PartialEq for & ' a mut T {
352380 #[ inline]
353381 fn eq ( & self , other : & & ' a mut T ) -> bool { * * self == * ( * other) }
354382 #[ inline]
355383 fn ne ( & self , other : & & ' a mut T ) -> bool { * * self != * ( * other) }
356384 }
385+ #[ unstable = "Trait is unstable." ]
357386 impl < ' a , T : PartialOrd > PartialOrd for & ' a mut T {
358387 #[ inline]
359388 fn partial_cmp ( & self , other : & & ' a mut T ) -> Option < Ordering > {
@@ -368,9 +397,11 @@ mod impls {
368397 #[ inline]
369398 fn gt ( & self , other : & & ' a mut T ) -> bool { * * self > * * other }
370399 }
400+ #[ unstable = "Trait is unstable." ]
371401 impl < ' a , T : Ord > Ord for & ' a mut T {
372402 #[ inline]
373403 fn cmp ( & self , other : & & ' a mut T ) -> Ordering { ( * * self ) . cmp ( * other) }
374404 }
405+ #[ unstable = "Trait is unstable." ]
375406 impl < ' a , T : Eq > Eq for & ' a mut T { }
376407}
0 commit comments