37
37
//! assert!(SketchyNum {num: 25} != SketchyNum {num: 57});
38
38
//! ```
39
39
40
+ #![ stable]
41
+
40
42
use option:: { Option , Some } ;
41
43
42
44
/// Trait for values that can be compared for equality and inequality.
@@ -53,6 +55,7 @@ use option::{Option, Some};
53
55
/// Eventually, this will be implemented by default for types that implement
54
56
/// `Eq`.
55
57
#[ lang="eq" ]
58
+ #[ unstable = "Definition may change slightly after trait reform" ]
56
59
pub trait PartialEq {
57
60
/// This method tests for `self` and `other` values to be equal, and is used by `==`.
58
61
fn eq ( & self , other : & Self ) -> bool ;
@@ -71,6 +74,7 @@ pub trait PartialEq {
71
74
/// - reflexive: `a == a`;
72
75
/// - symmetric: `a == b` implies `b == a`; and
73
76
/// - transitive: `a == b` and `b == c` implies `a == c`.
77
+ #[ unstable = "Definition may change slightly after trait reform" ]
74
78
pub trait Eq : PartialEq {
75
79
// FIXME #13101: this method is used solely by #[deriving] to
76
80
// assert that every component of a type implements #[deriving]
@@ -86,6 +90,7 @@ pub trait Eq: PartialEq {
86
90
87
91
/// An ordering is, e.g, a result of a comparison between two values.
88
92
#[ deriving( Clone , PartialEq , Show ) ]
93
+ #[ stable]
89
94
pub enum Ordering {
90
95
/// An ordering where a compared value is less [than another].
91
96
Less = -1 i,
@@ -104,6 +109,7 @@ pub enum Ordering {
104
109
/// true; and
105
110
/// - transitive, `a < b` and `b < c` implies `a < c`. The same must hold for
106
111
/// both `==` and `>`.
112
+ #[ unstable = "Definition may change slightly after trait reform" ]
107
113
pub trait Ord : Eq + PartialOrd {
108
114
/// This method returns an ordering between `self` and `other` values.
109
115
///
@@ -118,15 +124,18 @@ pub trait Ord: Eq + PartialOrd {
118
124
fn cmp ( & self , other : & Self ) -> Ordering ;
119
125
}
120
126
127
+ #[ unstable = "Trait is unstable." ]
121
128
impl Eq for Ordering { }
122
129
130
+ #[ unstable = "Trait is unstable." ]
123
131
impl Ord for Ordering {
124
132
#[ inline]
125
133
fn cmp ( & self , other : & Ordering ) -> Ordering {
126
134
( * self as int ) . cmp ( & ( * other as int ) )
127
135
}
128
136
}
129
137
138
+ #[ unstable = "Trait is unstable." ]
130
139
impl PartialOrd for Ordering {
131
140
#[ inline]
132
141
fn partial_cmp ( & self , other : & Ordering ) -> Option < Ordering > {
@@ -140,6 +149,7 @@ impl PartialOrd for Ordering {
140
149
/// If the first ordering is different, the first ordering is all that must be returned.
141
150
/// If the first ordering is equal, then second ordering is returned.
142
151
#[ inline]
152
+ #[ deprecated = "Just call .cmp() on an Ordering" ]
143
153
pub fn lexical_ordering ( o1 : Ordering , o2 : Ordering ) -> Ordering {
144
154
match o1 {
145
155
Equal => o2,
@@ -157,6 +167,7 @@ pub fn lexical_ordering(o1: Ordering, o2: Ordering) -> Ordering {
157
167
/// `NaN < 0 == false` and `NaN >= 0 == false` (cf. IEEE 754-2008 section
158
168
/// 5.11).
159
169
#[ lang="ord" ]
170
+ #[ unstable = "Definition may change slightly after trait reform" ]
160
171
pub trait PartialOrd : PartialEq {
161
172
/// This method returns an ordering between `self` and `other` values
162
173
/// if one exists.
@@ -202,19 +213,22 @@ pub trait PartialOrd: PartialEq {
202
213
/// of different types. The most common use case for this relation is
203
214
/// container types; e.g. it is often desirable to be able to use `&str`
204
215
/// values to look up entries in a container with `String` keys.
216
+ #[ experimental = "Better solutions may be discovered." ]
205
217
pub trait Equiv < T > {
206
218
/// Implement this function to decide equivalent values.
207
219
fn equiv ( & self , other : & T ) -> bool ;
208
220
}
209
221
210
222
/// Compare and return the minimum of two values.
211
223
#[ inline]
224
+ #[ stable]
212
225
pub fn min < T : Ord > ( v1 : T , v2 : T ) -> T {
213
226
if v1 < v2 { v1 } else { v2 }
214
227
}
215
228
216
229
/// Compare and return the maximum of two values.
217
230
#[ inline]
231
+ #[ stable]
218
232
pub fn max < T : Ord > ( v1 : T , v2 : T ) -> T {
219
233
if v1 > v2 { v1 } else { v2 }
220
234
}
@@ -227,6 +241,7 @@ mod impls {
227
241
228
242
macro_rules! eq_impl(
229
243
( $( $t: ty) * ) => ( $(
244
+ #[ unstable = "Trait is unstable." ]
230
245
impl PartialEq for $t {
231
246
#[ inline]
232
247
fn eq( & self , other: & $t) -> bool { ( * self ) == ( * other) }
@@ -236,6 +251,7 @@ mod impls {
236
251
) * )
237
252
)
238
253
254
+ #[ unstable = "Trait is unstable." ]
239
255
impl PartialEq for ( ) {
240
256
#[ inline]
241
257
fn eq ( & self , _other : & ( ) ) -> bool { true }
@@ -247,6 +263,7 @@ mod impls {
247
263
248
264
macro_rules! totaleq_impl(
249
265
( $( $t: ty) * ) => ( $(
266
+ #[ unstable = "Trait is unstable." ]
250
267
impl Eq for $t { }
251
268
) * )
252
269
)
@@ -255,6 +272,7 @@ mod impls {
255
272
256
273
macro_rules! ord_impl(
257
274
( $( $t: ty) * ) => ( $(
275
+ #[ unstable = "Trait is unstable." ]
258
276
impl PartialOrd for $t {
259
277
#[ inline]
260
278
fn partial_cmp( & self , other: & $t) -> Option <Ordering > {
@@ -277,13 +295,15 @@ mod impls {
277
295
) * )
278
296
)
279
297
298
+ #[ unstable = "Trait is unstable." ]
280
299
impl PartialOrd for ( ) {
281
300
#[ inline]
282
301
fn partial_cmp ( & self , _: & ( ) ) -> Option < Ordering > {
283
302
Some ( Equal )
284
303
}
285
304
}
286
305
306
+ #[ unstable = "Trait is unstable." ]
287
307
impl PartialOrd for bool {
288
308
#[ inline]
289
309
fn partial_cmp ( & self , other : & bool ) -> Option < Ordering > {
@@ -295,6 +315,7 @@ mod impls {
295
315
296
316
macro_rules! totalord_impl(
297
317
( $( $t: ty) * ) => ( $(
318
+ #[ unstable = "Trait is unstable." ]
298
319
impl Ord for $t {
299
320
#[ inline]
300
321
fn cmp( & self , other: & $t) -> Ordering {
@@ -306,11 +327,13 @@ mod impls {
306
327
) * )
307
328
)
308
329
330
+ #[ unstable = "Trait is unstable." ]
309
331
impl Ord for ( ) {
310
332
#[ inline]
311
333
fn cmp ( & self , _other : & ( ) ) -> Ordering { Equal }
312
334
}
313
335
336
+ #[ unstable = "Trait is unstable." ]
314
337
impl Ord for bool {
315
338
#[ inline]
316
339
fn cmp ( & self , other : & bool ) -> Ordering {
@@ -321,12 +344,14 @@ mod impls {
321
344
totalord_impl ! ( char uint u8 u16 u32 u64 int i8 i16 i32 i64 )
322
345
323
346
// & pointers
347
+ #[ unstable = "Trait is unstable." ]
324
348
impl < ' a , T : PartialEq > PartialEq for & ' a T {
325
349
#[ inline]
326
350
fn eq ( & self , other : & & ' a T ) -> bool { * ( * self ) == * ( * other) }
327
351
#[ inline]
328
352
fn ne ( & self , other : & & ' a T ) -> bool { * ( * self ) != * ( * other) }
329
353
}
354
+ #[ unstable = "Trait is unstable." ]
330
355
impl < ' a , T : PartialOrd > PartialOrd for & ' a T {
331
356
#[ inline]
332
357
fn partial_cmp ( & self , other : & & ' a T ) -> Option < Ordering > {
@@ -341,19 +366,23 @@ mod impls {
341
366
#[ inline]
342
367
fn gt ( & self , other : & & ' a T ) -> bool { * ( * self ) > * ( * other) }
343
368
}
369
+ #[ unstable = "Trait is unstable." ]
344
370
impl < ' a , T : Ord > Ord for & ' a T {
345
371
#[ inline]
346
372
fn cmp ( & self , other : & & ' a T ) -> Ordering { ( * * self ) . cmp ( * other) }
347
373
}
374
+ #[ unstable = "Trait is unstable." ]
348
375
impl < ' a , T : Eq > Eq for & ' a T { }
349
376
350
377
// &mut pointers
378
+ #[ unstable = "Trait is unstable." ]
351
379
impl < ' a , T : PartialEq > PartialEq for & ' a mut T {
352
380
#[ inline]
353
381
fn eq ( & self , other : & & ' a mut T ) -> bool { * * self == * ( * other) }
354
382
#[ inline]
355
383
fn ne ( & self , other : & & ' a mut T ) -> bool { * * self != * ( * other) }
356
384
}
385
+ #[ unstable = "Trait is unstable." ]
357
386
impl < ' a , T : PartialOrd > PartialOrd for & ' a mut T {
358
387
#[ inline]
359
388
fn partial_cmp ( & self , other : & & ' a mut T ) -> Option < Ordering > {
@@ -368,9 +397,11 @@ mod impls {
368
397
#[ inline]
369
398
fn gt ( & self , other : & & ' a mut T ) -> bool { * * self > * * other }
370
399
}
400
+ #[ unstable = "Trait is unstable." ]
371
401
impl < ' a , T : Ord > Ord for & ' a mut T {
372
402
#[ inline]
373
403
fn cmp ( & self , other : & & ' a mut T ) -> Ordering { ( * * self ) . cmp ( * other) }
374
404
}
405
+ #[ unstable = "Trait is unstable." ]
375
406
impl < ' a , T : Eq > Eq for & ' a mut T { }
376
407
}
0 commit comments