]> git.lizzy.rs Git - rust.git/blob - src/libcore/cmp.rs
dab549f784cf82bf68a175fa0d67b7423729b8c8
[rust.git] / src / libcore / cmp.rs
1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! Functionality for ordering and comparison.
12 //!
13 //! This module defines both `PartialOrd` and `PartialEq` traits which are used by the compiler to
14 //! implement comparison operators. Rust programs may implement `PartialOrd` to overload the `<`,
15 //! `<=`, `>`, and `>=` operators, and may implement `PartialEq` to overload the `==` and `!=`
16 //! operators.
17
18 #![stable(feature = "rust1", since = "1.0.0")]
19
20 use self::Ordering::*;
21
22 use marker::Sized;
23 use option::Option::{self, Some, None};
24
25 /// Trait for equality comparisons which are [partial equivalence relations](
26 /// http://en.wikipedia.org/wiki/Partial_equivalence_relation).
27 ///
28 /// This trait allows for partial equality, for types that do not have a full equivalence relation.
29 /// For example, in floating point numbers `NaN != NaN`, so floating point types implement
30 /// `PartialEq` but not `Eq`.
31 ///
32 /// Formally, the equality must be (for all `a`, `b` and `c`):
33 ///
34 /// - symmetric: `a == b` implies `b == a`; and
35 /// - transitive: `a == b` and `b == c` implies `a == c`.
36 ///
37 /// Note that these requirements mean that the trait itself must be implemented symmetrically and
38 /// transitively: if `T: PartialEq<U>` and `U: PartialEq<V>` then `U: PartialEq<T>` and `T:
39 /// PartialEq<V>`.
40 ///
41 /// PartialEq only requires the `eq` method to be implemented; `ne` is defined in terms of it by
42 /// default. Any manual implementation of `ne` *must* respect the rule that `eq` is a strict
43 /// inverse of `ne`; that is, `!(a == b)` if and only if `a != b`.
44 #[lang = "eq"]
45 #[stable(feature = "rust1", since = "1.0.0")]
46 pub trait PartialEq<Rhs: ?Sized = Self> {
47     /// This method tests for `self` and `other` values to be equal, and is used by `==`.
48     #[stable(feature = "rust1", since = "1.0.0")]
49     fn eq(&self, other: &Rhs) -> bool;
50
51     /// This method tests for `!=`.
52     #[inline]
53     #[stable(feature = "rust1", since = "1.0.0")]
54     fn ne(&self, other: &Rhs) -> bool { !self.eq(other) }
55 }
56
57 /// Trait for equality comparisons which are [equivalence relations](
58 /// https://en.wikipedia.org/wiki/Equivalence_relation).
59 ///
60 /// This means, that in addition to `a == b` and `a != b` being strict inverses, the equality must
61 /// be (for all `a`, `b` and `c`):
62 ///
63 /// - reflexive: `a == a`;
64 /// - symmetric: `a == b` implies `b == a`; and
65 /// - transitive: `a == b` and `b == c` implies `a == c`.
66 ///
67 /// This property cannot be checked by the compiler, and therefore `Eq` implies
68 /// `PartialEq`, and has no extra methods.
69 #[stable(feature = "rust1", since = "1.0.0")]
70 pub trait Eq: PartialEq<Self> {
71     // FIXME #13101: this method is used solely by #[deriving] to
72     // assert that every component of a type implements #[deriving]
73     // itself, the current deriving infrastructure means doing this
74     // assertion without using a method on this trait is nearly
75     // impossible.
76     //
77     // This should never be implemented by hand.
78     #[doc(hidden)]
79     #[inline(always)]
80     #[stable(feature = "rust1", since = "1.0.0")]
81     fn assert_receiver_is_total_eq(&self) {}
82 }
83
84 /// An `Ordering` is the result of a comparison between two values.
85 ///
86 /// # Examples
87 ///
88 /// ```
89 /// use std::cmp::Ordering;
90 ///
91 /// let result = 1.cmp(&2);
92 /// assert_eq!(Ordering::Less, result);
93 ///
94 /// let result = 1.cmp(&1);
95 /// assert_eq!(Ordering::Equal, result);
96 ///
97 /// let result = 2.cmp(&1);
98 /// assert_eq!(Ordering::Greater, result);
99 /// ```
100 #[derive(Clone, Copy, PartialEq, Debug)]
101 #[stable(feature = "rust1", since = "1.0.0")]
102 pub enum Ordering {
103     /// An ordering where a compared value is less [than another].
104     #[stable(feature = "rust1", since = "1.0.0")]
105     Less = -1,
106     /// An ordering where a compared value is equal [to another].
107     #[stable(feature = "rust1", since = "1.0.0")]
108     Equal = 0,
109     /// An ordering where a compared value is greater [than another].
110     #[stable(feature = "rust1", since = "1.0.0")]
111     Greater = 1,
112 }
113
114 impl Ordering {
115     /// Reverse the `Ordering`.
116     ///
117     /// * `Less` becomes `Greater`.
118     /// * `Greater` becomes `Less`.
119     /// * `Equal` becomes `Equal`.
120     ///
121     /// # Examples
122     ///
123     /// Basic behavior:
124     ///
125     /// ```
126     /// use std::cmp::Ordering;
127     ///
128     /// assert_eq!(Ordering::Less.reverse(), Ordering::Greater);
129     /// assert_eq!(Ordering::Equal.reverse(), Ordering::Equal);
130     /// assert_eq!(Ordering::Greater.reverse(), Ordering::Less);
131     /// ```
132     ///
133     /// This method can be used to reverse a comparison:
134     ///
135     /// ```
136     /// use std::cmp::Ordering;
137     ///
138     /// let mut data: &mut [_] = &mut [2, 10, 5, 8];
139     ///
140     /// // sort the array from largest to smallest.
141     /// data.sort_by(|a, b| a.cmp(b).reverse());
142     ///
143     /// let b: &mut [_] = &mut [10, 8, 5, 2];
144     /// assert!(data == b);
145     /// ```
146     #[inline]
147     #[stable(feature = "rust1", since = "1.0.0")]
148     pub fn reverse(self) -> Ordering {
149         unsafe {
150             // this compiles really nicely (to a single instruction);
151             // an explicit match has a pile of branches and
152             // comparisons.
153             //
154             // NB. it is safe because of the explicit discriminants
155             // given above.
156             ::mem::transmute::<_, Ordering>(-(self as i8))
157         }
158     }
159 }
160
161 /// Trait for types that form a [total order](https://en.wikipedia.org/wiki/Total_order).
162 ///
163 /// An order is a total order if it is (for all `a`, `b` and `c`):
164 ///
165 /// - total and antisymmetric: exactly one of `a < b`, `a == b` or `a > b` is true; and
166 /// - transitive, `a < b` and `b < c` implies `a < c`. The same must hold for both `==` and `>`.
167 #[stable(feature = "rust1", since = "1.0.0")]
168 pub trait Ord: Eq + PartialOrd<Self> {
169     /// This method returns an `Ordering` between `self` and `other`.
170     ///
171     /// By convention, `self.cmp(&other)` returns the ordering matching the expression
172     /// `self <operator> other` if true.
173     ///
174     /// # Examples
175     ///
176     /// ```
177     /// use std::cmp::Ordering;
178     ///
179     /// assert_eq!(5.cmp(&10), Ordering::Less);
180     /// assert_eq!(10.cmp(&5), Ordering::Greater);
181     /// assert_eq!(5.cmp(&5), Ordering::Equal);
182     /// ```
183     #[stable(feature = "rust1", since = "1.0.0")]
184     fn cmp(&self, other: &Self) -> Ordering;
185 }
186
187 #[stable(feature = "rust1", since = "1.0.0")]
188 impl Eq for Ordering {}
189
190 #[stable(feature = "rust1", since = "1.0.0")]
191 impl Ord for Ordering {
192     #[inline]
193     #[stable(feature = "rust1", since = "1.0.0")]
194     fn cmp(&self, other: &Ordering) -> Ordering {
195         (*self as i32).cmp(&(*other as i32))
196     }
197 }
198
199 #[stable(feature = "rust1", since = "1.0.0")]
200 impl PartialOrd for Ordering {
201     #[inline]
202     #[stable(feature = "rust1", since = "1.0.0")]
203     fn partial_cmp(&self, other: &Ordering) -> Option<Ordering> {
204         (*self as i32).partial_cmp(&(*other as i32))
205     }
206 }
207
208 /// Trait for values that can be compared for a sort-order.
209 ///
210 /// The comparison must satisfy, for all `a`, `b` and `c`:
211 ///
212 /// - antisymmetry: if `a < b` then `!(a > b)` and vice versa; and
213 /// - transitivity: `a < b` and `b < c` implies `a < c`. The same must hold for both `==` and `>`.
214 ///
215 /// Note that these requirements mean that the trait itself must be implemented symmetrically and
216 /// transitively: if `T: PartialOrd<U>` and `U: PartialOrd<V>` then `U: PartialOrd<T>` and `T:
217 /// PartialOrd<V>`.
218 ///
219 /// PartialOrd only requires implementation of the `partial_cmp` method, with the others generated
220 /// from default implementations.
221 ///
222 /// However it remains possible to implement the others separately for types which do not have a
223 /// total order. For example, for floating point numbers, `NaN < 0 == false` and `NaN >= 0 ==
224 /// false` (cf. IEEE 754-2008 section 5.11).
225 #[lang = "ord"]
226 #[stable(feature = "rust1", since = "1.0.0")]
227 pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
228     /// This method returns an ordering between `self` and `other` values if one exists.
229     ///
230     /// # Examples
231     ///
232     /// ```
233     /// use std::cmp::Ordering;
234     ///
235     /// let result = 1.0.partial_cmp(&2.0);
236     /// assert_eq!(result, Some(Ordering::Less));
237     ///
238     /// let result = 1.0.partial_cmp(&1.0);
239     /// assert_eq!(result, Some(Ordering::Equal));
240     ///
241     /// let result = 2.0.partial_cmp(&1.0);
242     /// assert_eq!(result, Some(Ordering::Greater));
243     /// ```
244     ///
245     /// When comparison is impossible:
246     ///
247     /// ```
248     /// let result = std::f64::NAN.partial_cmp(&1.0);
249     /// assert_eq!(result, None);
250     /// ```
251     #[stable(feature = "rust1", since = "1.0.0")]
252     fn partial_cmp(&self, other: &Rhs) -> Option<Ordering>;
253
254     /// This method tests less than (for `self` and `other`) and is used by the `<` operator.
255     ///
256     /// # Examples
257     ///
258     /// ```
259     /// use std::cmp::Ordering;
260     ///
261     /// let result = 1.0 < 2.0;
262     /// assert_eq!(result, true);
263     ///
264     /// let result = 2.0 < 1.0;
265     /// assert_eq!(result, false);
266     /// ```
267     #[inline]
268     #[stable(feature = "rust1", since = "1.0.0")]
269     fn lt(&self, other: &Rhs) -> bool {
270         match self.partial_cmp(other) {
271             Some(Less) => true,
272             _ => false,
273         }
274     }
275
276     /// This method tests less than or equal to (for `self` and `other`) and is used by the `<=`
277     /// operator.
278     ///
279     /// # Examples
280     ///
281     /// ```
282     /// let result = 1.0 <= 2.0;
283     /// assert_eq!(result, true);
284     ///
285     /// let result = 2.0 <= 2.0;
286     /// assert_eq!(result, true);
287     /// ```
288     #[inline]
289     #[stable(feature = "rust1", since = "1.0.0")]
290     fn le(&self, other: &Rhs) -> bool {
291         match self.partial_cmp(other) {
292             Some(Less) | Some(Equal) => true,
293             _ => false,
294         }
295     }
296
297     /// This method tests greater than (for `self` and `other`) and is used by the `>` operator.
298     ///
299     /// # Examples
300     ///
301     /// ```
302     /// let result = 1.0 > 2.0;
303     /// assert_eq!(result, false);
304     ///
305     /// let result = 2.0 > 2.0;
306     /// assert_eq!(result, false);
307     /// ```
308     #[inline]
309     #[stable(feature = "rust1", since = "1.0.0")]
310     fn gt(&self, other: &Rhs) -> bool {
311         match self.partial_cmp(other) {
312             Some(Greater) => true,
313             _ => false,
314         }
315     }
316
317     /// This method tests greater than or equal to (for `self` and `other`) and is used by the `>=`
318     /// operator.
319     ///
320     /// # Examples
321     ///
322     /// ```
323     /// let result = 2.0 >= 1.0;
324     /// assert_eq!(result, true);
325     ///
326     /// let result = 2.0 >= 2.0;
327     /// assert_eq!(result, true);
328     /// ```
329     #[inline]
330     #[stable(feature = "rust1", since = "1.0.0")]
331     fn ge(&self, other: &Rhs) -> bool {
332         match self.partial_cmp(other) {
333             Some(Greater) | Some(Equal) => true,
334             _ => false,
335         }
336     }
337 }
338
339 /// Compare and return the minimum of two values.
340 ///
341 /// Returns the first argument if the comparison determines them to be equal.
342 ///
343 /// # Examples
344 ///
345 /// ```
346 /// use std::cmp;
347 ///
348 /// assert_eq!(1, cmp::min(1, 2));
349 /// assert_eq!(2, cmp::min(2, 2));
350 /// ```
351 #[inline]
352 #[stable(feature = "rust1", since = "1.0.0")]
353 pub fn min<T: Ord>(v1: T, v2: T) -> T {
354     if v1 <= v2 { v1 } else { v2 }
355 }
356
357 /// Compare and return the maximum of two values.
358 ///
359 /// Returns the second argument if the comparison determines them to be equal.
360 ///
361 /// # Examples
362 ///
363 /// ```
364 /// use std::cmp;
365 ///
366 /// assert_eq!(2, cmp::max(1, 2));
367 /// assert_eq!(2, cmp::max(2, 2));
368 /// ```
369 #[inline]
370 #[stable(feature = "rust1", since = "1.0.0")]
371 pub fn max<T: Ord>(v1: T, v2: T) -> T {
372     if v2 >= v1 { v2 } else { v1 }
373 }
374
375 /// Compare and return the minimum of two values if there is one.
376 ///
377 /// Returns the first argument if the comparison determines them to be equal.
378 ///
379 /// # Examples
380 ///
381 /// ```
382 /// # #![feature(core)]
383 /// use std::cmp;
384 ///
385 /// assert_eq!(Some(1), cmp::partial_min(1, 2));
386 /// assert_eq!(Some(2), cmp::partial_min(2, 2));
387 /// ```
388 ///
389 /// When comparison is impossible:
390 ///
391 /// ```
392 /// # #![feature(core)]
393 /// use std::cmp;
394 ///
395 /// let result = cmp::partial_min(std::f64::NAN, 1.0);
396 /// assert_eq!(result, None);
397 /// ```
398 #[inline]
399 #[unstable(feature = "core")]
400 pub fn partial_min<T: PartialOrd>(v1: T, v2: T) -> Option<T> {
401     match v1.partial_cmp(&v2) {
402         Some(Less) | Some(Equal) => Some(v1),
403         Some(Greater) => Some(v2),
404         None => None
405     }
406 }
407
408 /// Compare and return the maximum of two values if there is one.
409 ///
410 /// Returns the second argument if the comparison determines them to be equal.
411 ///
412 /// # Examples
413 ///
414 /// ```
415 /// # #![feature(core)]
416 /// use std::cmp;
417 ///
418 /// assert_eq!(Some(2), cmp::partial_max(1, 2));
419 /// assert_eq!(Some(2), cmp::partial_max(2, 2));
420 /// ```
421 ///
422 /// When comparison is impossible:
423 ///
424 /// ```
425 /// # #![feature(core)]
426 /// use std::cmp;
427 ///
428 /// let result = cmp::partial_max(std::f64::NAN, 1.0);
429 /// assert_eq!(result, None);
430 /// ```
431 #[inline]
432 #[unstable(feature = "core")]
433 pub fn partial_max<T: PartialOrd>(v1: T, v2: T) -> Option<T> {
434     match v1.partial_cmp(&v2) {
435         Some(Equal) | Some(Less) => Some(v2),
436         Some(Greater) => Some(v1),
437         None => None
438     }
439 }
440
441 // Implementation of PartialEq, Eq, PartialOrd and Ord for primitive types
442 mod impls {
443     use cmp::{PartialOrd, Ord, PartialEq, Eq, Ordering};
444     use cmp::Ordering::{Less, Greater, Equal};
445     use marker::Sized;
446     use option::Option;
447     use option::Option::{Some, None};
448
449     macro_rules! partial_eq_impl {
450         ($($t:ty)*) => ($(
451             #[stable(feature = "rust1", since = "1.0.0")]
452             impl PartialEq for $t {
453                 #[inline]
454                 fn eq(&self, other: &$t) -> bool { (*self) == (*other) }
455                 #[inline]
456                 fn ne(&self, other: &$t) -> bool { (*self) != (*other) }
457             }
458         )*)
459     }
460
461     #[stable(feature = "rust1", since = "1.0.0")]
462     impl PartialEq for () {
463         #[inline]
464         fn eq(&self, _other: &()) -> bool { true }
465         #[inline]
466         fn ne(&self, _other: &()) -> bool { false }
467     }
468
469     partial_eq_impl! {
470         bool char usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64
471     }
472
473     macro_rules! eq_impl {
474         ($($t:ty)*) => ($(
475             #[stable(feature = "rust1", since = "1.0.0")]
476             impl Eq for $t {}
477         )*)
478     }
479
480     eq_impl! { () bool char usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
481
482     macro_rules! partial_ord_impl {
483         ($($t:ty)*) => ($(
484             #[stable(feature = "rust1", since = "1.0.0")]
485             impl PartialOrd for $t {
486                 #[inline]
487                 fn partial_cmp(&self, other: &$t) -> Option<Ordering> {
488                     match (self <= other, self >= other) {
489                         (false, false) => None,
490                         (false, true) => Some(Greater),
491                         (true, false) => Some(Less),
492                         (true, true) => Some(Equal),
493                     }
494                 }
495                 #[inline]
496                 fn lt(&self, other: &$t) -> bool { (*self) < (*other) }
497                 #[inline]
498                 fn le(&self, other: &$t) -> bool { (*self) <= (*other) }
499                 #[inline]
500                 fn ge(&self, other: &$t) -> bool { (*self) >= (*other) }
501                 #[inline]
502                 fn gt(&self, other: &$t) -> bool { (*self) > (*other) }
503             }
504         )*)
505     }
506
507     #[stable(feature = "rust1", since = "1.0.0")]
508     impl PartialOrd for () {
509         #[inline]
510         fn partial_cmp(&self, _: &()) -> Option<Ordering> {
511             Some(Equal)
512         }
513     }
514
515     #[stable(feature = "rust1", since = "1.0.0")]
516     impl PartialOrd for bool {
517         #[inline]
518         fn partial_cmp(&self, other: &bool) -> Option<Ordering> {
519             (*self as u8).partial_cmp(&(*other as u8))
520         }
521     }
522
523     partial_ord_impl! { char usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
524
525     macro_rules! ord_impl {
526         ($($t:ty)*) => ($(
527             #[stable(feature = "rust1", since = "1.0.0")]
528             impl Ord for $t {
529                 #[inline]
530                 fn cmp(&self, other: &$t) -> Ordering {
531                     if *self < *other { Less }
532                     else if *self > *other { Greater }
533                     else { Equal }
534                 }
535             }
536         )*)
537     }
538
539     #[stable(feature = "rust1", since = "1.0.0")]
540     impl Ord for () {
541         #[inline]
542         fn cmp(&self, _other: &()) -> Ordering { Equal }
543     }
544
545     #[stable(feature = "rust1", since = "1.0.0")]
546     impl Ord for bool {
547         #[inline]
548         fn cmp(&self, other: &bool) -> Ordering {
549             (*self as u8).cmp(&(*other as u8))
550         }
551     }
552
553     ord_impl! { char usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
554
555     // & pointers
556
557     #[stable(feature = "rust1", since = "1.0.0")]
558     impl<'a, 'b, A: ?Sized, B: ?Sized> PartialEq<&'b B> for &'a A where A: PartialEq<B> {
559         #[inline]
560         fn eq(&self, other: & &'b B) -> bool { PartialEq::eq(*self, *other) }
561         #[inline]
562         fn ne(&self, other: & &'b B) -> bool { PartialEq::ne(*self, *other) }
563     }
564     #[stable(feature = "rust1", since = "1.0.0")]
565     impl<'a, 'b, A: ?Sized, B: ?Sized> PartialOrd<&'b B> for &'a A where A: PartialOrd<B> {
566         #[inline]
567         fn partial_cmp(&self, other: &&'b B) -> Option<Ordering> {
568             PartialOrd::partial_cmp(*self, *other)
569         }
570         #[inline]
571         fn lt(&self, other: & &'b B) -> bool { PartialOrd::lt(*self, *other) }
572         #[inline]
573         fn le(&self, other: & &'b B) -> bool { PartialOrd::le(*self, *other) }
574         #[inline]
575         fn ge(&self, other: & &'b B) -> bool { PartialOrd::ge(*self, *other) }
576         #[inline]
577         fn gt(&self, other: & &'b B) -> bool { PartialOrd::gt(*self, *other) }
578     }
579     #[stable(feature = "rust1", since = "1.0.0")]
580     impl<'a, A: ?Sized> Ord for &'a A where A: Ord {
581         #[inline]
582         fn cmp(&self, other: & &'a A) -> Ordering { Ord::cmp(*self, *other) }
583     }
584     #[stable(feature = "rust1", since = "1.0.0")]
585     impl<'a, A: ?Sized> Eq for &'a A where A: Eq {}
586
587     // &mut pointers
588
589     #[stable(feature = "rust1", since = "1.0.0")]
590     impl<'a, 'b, A: ?Sized, B: ?Sized> PartialEq<&'b mut B> for &'a mut A where A: PartialEq<B> {
591         #[inline]
592         fn eq(&self, other: &&'b mut B) -> bool { PartialEq::eq(*self, *other) }
593         #[inline]
594         fn ne(&self, other: &&'b mut B) -> bool { PartialEq::ne(*self, *other) }
595     }
596     #[stable(feature = "rust1", since = "1.0.0")]
597     impl<'a, 'b, A: ?Sized, B: ?Sized> PartialOrd<&'b mut B> for &'a mut A where A: PartialOrd<B> {
598         #[inline]
599         fn partial_cmp(&self, other: &&'b mut B) -> Option<Ordering> {
600             PartialOrd::partial_cmp(*self, *other)
601         }
602         #[inline]
603         fn lt(&self, other: &&'b mut B) -> bool { PartialOrd::lt(*self, *other) }
604         #[inline]
605         fn le(&self, other: &&'b mut B) -> bool { PartialOrd::le(*self, *other) }
606         #[inline]
607         fn ge(&self, other: &&'b mut B) -> bool { PartialOrd::ge(*self, *other) }
608         #[inline]
609         fn gt(&self, other: &&'b mut B) -> bool { PartialOrd::gt(*self, *other) }
610     }
611     #[stable(feature = "rust1", since = "1.0.0")]
612     impl<'a, A: ?Sized> Ord for &'a mut A where A: Ord {
613         #[inline]
614         fn cmp(&self, other: &&'a mut A) -> Ordering { Ord::cmp(*self, *other) }
615     }
616     #[stable(feature = "rust1", since = "1.0.0")]
617     impl<'a, A: ?Sized> Eq for &'a mut A where A: Eq {}
618
619     #[stable(feature = "rust1", since = "1.0.0")]
620     impl<'a, 'b, A: ?Sized, B: ?Sized> PartialEq<&'b mut B> for &'a A where A: PartialEq<B> {
621         #[inline]
622         fn eq(&self, other: &&'b mut B) -> bool { PartialEq::eq(*self, *other) }
623         #[inline]
624         fn ne(&self, other: &&'b mut B) -> bool { PartialEq::ne(*self, *other) }
625     }
626
627     #[stable(feature = "rust1", since = "1.0.0")]
628     impl<'a, 'b, A: ?Sized, B: ?Sized> PartialEq<&'b B> for &'a mut A where A: PartialEq<B> {
629         #[inline]
630         fn eq(&self, other: &&'b B) -> bool { PartialEq::eq(*self, *other) }
631         #[inline]
632         fn ne(&self, other: &&'b B) -> bool { PartialEq::ne(*self, *other) }
633     }
634 }