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.
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.
11 //! Functionality for ordering and comparison.
13 //! This module defines both [`PartialOrd`] and [`PartialEq`] traits which are used
14 //! by the compiler to implement comparison operators. Rust programs may
15 //! implement [`PartialOrd`] to overload the `<`, `<=`, `>`, and `>=` operators,
16 //! and may implement [`PartialEq`] to overload the `==` and `!=` operators.
18 //! [`PartialOrd`]: trait.PartialOrd.html
19 //! [`PartialEq`]: trait.PartialEq.html
27 //! // these two lines are equivalent
28 //! assert_eq!(x < y, true);
29 //! assert_eq!(x.lt(&y), true);
31 //! // these two lines are also equivalent
32 //! assert_eq!(x == y, false);
33 //! assert_eq!(x.eq(&y), false);
36 #![stable(feature = "rust1", since = "1.0.0")]
38 use self::Ordering::*;
40 /// Trait for equality comparisons which are [partial equivalence
41 /// relations](http://en.wikipedia.org/wiki/Partial_equivalence_relation).
43 /// This trait allows for partial equality, for types that do not have a full
44 /// equivalence relation. For example, in floating point numbers `NaN != NaN`,
45 /// so floating point types implement `PartialEq` but not `Eq`.
47 /// Formally, the equality must be (for all `a`, `b` and `c`):
49 /// - symmetric: `a == b` implies `b == a`; and
50 /// - transitive: `a == b` and `b == c` implies `a == c`.
52 /// Note that these requirements mean that the trait itself must be implemented
53 /// symmetrically and transitively: if `T: PartialEq<U>` and `U: PartialEq<V>`
54 /// then `U: PartialEq<T>` and `T: PartialEq<V>`.
58 /// This trait can be used with `#[derive]`. When `derive`d on structs, two
59 /// instances are equal if all fields are equal, and not equal if any fields
60 /// are not equal. When `derive`d on enums, each variant is equal to itself
61 /// and not equal to the other variants.
63 /// ## How can I implement `PartialEq`?
65 /// PartialEq only requires the `eq` method to be implemented; `ne` is defined
66 /// in terms of it by default. Any manual implementation of `ne` *must* respect
67 /// the rule that `eq` is a strict inverse of `ne`; that is, `!(a == b)` if and
70 /// An example implementation for a domain in which two books are considered
71 /// the same book if their ISBN matches, even if the formats differ:
74 /// enum BookFormat { Paperback, Hardback, Ebook }
77 /// format: BookFormat,
80 /// impl PartialEq for Book {
81 /// fn eq(&self, other: &Book) -> bool {
82 /// self.isbn == other.isbn
86 /// let b1 = Book { isbn: 3, format: BookFormat::Paperback };
87 /// let b2 = Book { isbn: 3, format: BookFormat::Ebook };
88 /// let b3 = Book { isbn: 10, format: BookFormat::Paperback };
90 /// assert!(b1 == b2);
91 /// assert!(b1 != b3);
100 /// assert_eq!(x == y, false);
101 /// assert_eq!(x.eq(&y), false);
104 #[stable(feature = "rust1", since = "1.0.0")]
105 pub trait PartialEq<Rhs: ?Sized = Self> {
106 /// This method tests for `self` and `other` values to be equal, and is used
108 #[stable(feature = "rust1", since = "1.0.0")]
109 fn eq(&self, other: &Rhs) -> bool;
111 /// This method tests for `!=`.
113 #[stable(feature = "rust1", since = "1.0.0")]
114 fn ne(&self, other: &Rhs) -> bool { !self.eq(other) }
117 /// Trait for equality comparisons which are [equivalence relations](
118 /// https://en.wikipedia.org/wiki/Equivalence_relation).
120 /// This means, that in addition to `a == b` and `a != b` being strict inverses, the equality must
121 /// be (for all `a`, `b` and `c`):
123 /// - reflexive: `a == a`;
124 /// - symmetric: `a == b` implies `b == a`; and
125 /// - transitive: `a == b` and `b == c` implies `a == c`.
127 /// This property cannot be checked by the compiler, and therefore `Eq` implies
128 /// `PartialEq`, and has no extra methods.
132 /// This trait can be used with `#[derive]`. When `derive`d, because `Eq` has
133 /// no extra methods, it is only informing the compiler that this is an
134 /// equivalence relation rather than a partial equivalence relation. Note that
135 /// the `derive` strategy requires all fields are `Eq`, which isn't
138 /// ## How can I implement `Eq`?
140 /// If you cannot use the `derive` strategy, specify that your type implements
141 /// `Eq`, which has no methods:
144 /// enum BookFormat { Paperback, Hardback, Ebook }
147 /// format: BookFormat,
149 /// impl PartialEq for Book {
150 /// fn eq(&self, other: &Book) -> bool {
151 /// self.isbn == other.isbn
154 /// impl Eq for Book {}
156 #[stable(feature = "rust1", since = "1.0.0")]
157 pub trait Eq: PartialEq<Self> {
158 // FIXME #13101: this method is used solely by #[deriving] to
159 // assert that every component of a type implements #[deriving]
160 // itself, the current deriving infrastructure means doing this
161 // assertion without using a method on this trait is nearly
164 // This should never be implemented by hand.
167 #[stable(feature = "rust1", since = "1.0.0")]
168 fn assert_receiver_is_total_eq(&self) {}
171 // FIXME: this struct is used solely by #[derive] to
172 // assert that every component of a type implements Eq.
174 // This struct should never appear in user code.
176 #[allow(missing_debug_implementations)]
177 #[unstable(feature = "derive_eq",
178 reason = "deriving hack, should not be public",
180 pub struct AssertParamIsEq<T: Eq + ?Sized> { _field: ::marker::PhantomData<T> }
182 /// An `Ordering` is the result of a comparison between two values.
187 /// use std::cmp::Ordering;
189 /// let result = 1.cmp(&2);
190 /// assert_eq!(Ordering::Less, result);
192 /// let result = 1.cmp(&1);
193 /// assert_eq!(Ordering::Equal, result);
195 /// let result = 2.cmp(&1);
196 /// assert_eq!(Ordering::Greater, result);
198 #[derive(Clone, Copy, PartialEq, Debug, Hash)]
199 #[stable(feature = "rust1", since = "1.0.0")]
201 /// An ordering where a compared value is less [than another].
202 #[stable(feature = "rust1", since = "1.0.0")]
204 /// An ordering where a compared value is equal [to another].
205 #[stable(feature = "rust1", since = "1.0.0")]
207 /// An ordering where a compared value is greater [than another].
208 #[stable(feature = "rust1", since = "1.0.0")]
213 /// Reverse the `Ordering`.
215 /// * `Less` becomes `Greater`.
216 /// * `Greater` becomes `Less`.
217 /// * `Equal` becomes `Equal`.
224 /// use std::cmp::Ordering;
226 /// assert_eq!(Ordering::Less.reverse(), Ordering::Greater);
227 /// assert_eq!(Ordering::Equal.reverse(), Ordering::Equal);
228 /// assert_eq!(Ordering::Greater.reverse(), Ordering::Less);
231 /// This method can be used to reverse a comparison:
234 /// let mut data: &mut [_] = &mut [2, 10, 5, 8];
236 /// // sort the array from largest to smallest.
237 /// data.sort_by(|a, b| a.cmp(b).reverse());
239 /// let b: &mut [_] = &mut [10, 8, 5, 2];
240 /// assert!(data == b);
243 #[stable(feature = "rust1", since = "1.0.0")]
244 pub fn reverse(self) -> Ordering {
252 /// Chains two orderings.
254 /// Returns `self` when it's not `Equal`. Otherwise returns `other`.
258 /// #![feature(ordering_chaining)]
260 /// use std::cmp::Ordering;
262 /// let result = Ordering::Equal.then(Ordering::Less);
263 /// assert_eq!(result, Ordering::Less);
265 /// let result = Ordering::Less.then(Ordering::Equal);
266 /// assert_eq!(result, Ordering::Less);
268 /// let result = Ordering::Less.then(Ordering::Greater);
269 /// assert_eq!(result, Ordering::Less);
271 /// let result = Ordering::Equal.then(Ordering::Equal);
272 /// assert_eq!(result, Ordering::Equal);
274 /// let x: (i64, i64, i64) = (1, 2, 7);
275 /// let y: (i64, i64, i64) = (1, 5, 3);
276 /// let result = x.0.cmp(&y.0).then(x.1.cmp(&y.1)).then(x.2.cmp(&y.2));
278 /// assert_eq!(result, Ordering::Less);
280 #[unstable(feature = "ordering_chaining", issue = "37053")]
281 pub fn then(self, other: Ordering) -> Ordering {
288 /// Chains the ordering with the given function.
290 /// Returns `self` when it's not `Equal`. Otherwise calls `f` and returns
296 /// #![feature(ordering_chaining)]
298 /// use std::cmp::Ordering;
300 /// let result = Ordering::Equal.then_with(|| Ordering::Less);
301 /// assert_eq!(result, Ordering::Less);
303 /// let result = Ordering::Less.then_with(|| Ordering::Equal);
304 /// assert_eq!(result, Ordering::Less);
306 /// let result = Ordering::Less.then_with(|| Ordering::Greater);
307 /// assert_eq!(result, Ordering::Less);
309 /// let result = Ordering::Equal.then_with(|| Ordering::Equal);
310 /// assert_eq!(result, Ordering::Equal);
312 /// let x: (i64, i64, i64) = (1, 2, 7);
313 /// let y: (i64, i64, i64) = (1, 5, 3);
314 /// let result = x.0.cmp(&y.0).then_with(|| x.1.cmp(&y.1)).then_with(|| x.2.cmp(&y.2));
316 /// assert_eq!(result, Ordering::Less);
318 #[unstable(feature = "ordering_chaining", issue = "37053")]
319 pub fn then_with<F: FnOnce() -> Ordering>(self, f: F) -> Ordering {
327 /// Trait for types that form a [total order](https://en.wikipedia.org/wiki/Total_order).
329 /// An order is a total order if it is (for all `a`, `b` and `c`):
331 /// - total and antisymmetric: exactly one of `a < b`, `a == b` or `a > b` is true; and
332 /// - transitive, `a < b` and `b < c` implies `a < c`. The same must hold for both `==` and `>`.
336 /// This trait can be used with `#[derive]`. When `derive`d, it will produce a lexicographic
337 /// ordering based on the top-to-bottom declaration order of the struct's members.
339 /// ## How can I implement `Ord`?
341 /// `Ord` requires that the type also be `PartialOrd` and `Eq` (which requires `PartialEq`).
343 /// Then you must define an implementation for `cmp()`. You may find it useful to use
344 /// `cmp()` on your type's fields.
346 /// Here's an example where you want to sort people by height only, disregarding `id`
350 /// use std::cmp::Ordering;
359 /// impl Ord for Person {
360 /// fn cmp(&self, other: &Person) -> Ordering {
361 /// self.height.cmp(&other.height)
365 /// impl PartialOrd for Person {
366 /// fn partial_cmp(&self, other: &Person) -> Option<Ordering> {
367 /// Some(self.cmp(other))
371 /// impl PartialEq for Person {
372 /// fn eq(&self, other: &Person) -> bool {
373 /// self.height == other.height
377 #[stable(feature = "rust1", since = "1.0.0")]
378 pub trait Ord: Eq + PartialOrd<Self> {
379 /// This method returns an `Ordering` between `self` and `other`.
381 /// By convention, `self.cmp(&other)` returns the ordering matching the expression
382 /// `self <operator> other` if true.
387 /// use std::cmp::Ordering;
389 /// assert_eq!(5.cmp(&10), Ordering::Less);
390 /// assert_eq!(10.cmp(&5), Ordering::Greater);
391 /// assert_eq!(5.cmp(&5), Ordering::Equal);
393 #[stable(feature = "rust1", since = "1.0.0")]
394 fn cmp(&self, other: &Self) -> Ordering;
397 #[stable(feature = "rust1", since = "1.0.0")]
398 impl Eq for Ordering {}
400 #[stable(feature = "rust1", since = "1.0.0")]
401 impl Ord for Ordering {
403 fn cmp(&self, other: &Ordering) -> Ordering {
404 (*self as i32).cmp(&(*other as i32))
408 #[stable(feature = "rust1", since = "1.0.0")]
409 impl PartialOrd for Ordering {
411 fn partial_cmp(&self, other: &Ordering) -> Option<Ordering> {
412 (*self as i32).partial_cmp(&(*other as i32))
416 /// Trait for values that can be compared for a sort-order.
418 /// The comparison must satisfy, for all `a`, `b` and `c`:
420 /// - antisymmetry: if `a < b` then `!(a > b)`, as well as `a > b` implying `!(a < b)`; and
421 /// - transitivity: `a < b` and `b < c` implies `a < c`. The same must hold for both `==` and `>`.
423 /// Note that these requirements mean that the trait itself must be implemented symmetrically and
424 /// transitively: if `T: PartialOrd<U>` and `U: PartialOrd<V>` then `U: PartialOrd<T>` and `T:
429 /// This trait can be used with `#[derive]`. When `derive`d, it will produce a lexicographic
430 /// ordering based on the top-to-bottom declaration order of the struct's members.
432 /// ## How can I implement `PartialOrd`?
434 /// PartialOrd only requires implementation of the `partial_cmp` method, with the others generated
435 /// from default implementations.
437 /// However it remains possible to implement the others separately for types which do not have a
438 /// total order. For example, for floating point numbers, `NaN < 0 == false` and `NaN >= 0 ==
439 /// false` (cf. IEEE 754-2008 section 5.11).
441 /// `PartialOrd` requires your type to be `PartialEq`.
443 /// If your type is `Ord`, you can implement `partial_cmp()` by using `cmp()`:
446 /// use std::cmp::Ordering;
455 /// impl PartialOrd for Person {
456 /// fn partial_cmp(&self, other: &Person) -> Option<Ordering> {
457 /// Some(self.cmp(other))
461 /// impl Ord for Person {
462 /// fn cmp(&self, other: &Person) -> Ordering {
463 /// self.height.cmp(&other.height)
467 /// impl PartialEq for Person {
468 /// fn eq(&self, other: &Person) -> bool {
469 /// self.height == other.height
474 /// You may also find it useful to use `partial_cmp()` on your type's fields. Here
475 /// is an example of `Person` types who have a floating-point `height` field that
476 /// is the only field to be used for sorting:
479 /// use std::cmp::Ordering;
487 /// impl PartialOrd for Person {
488 /// fn partial_cmp(&self, other: &Person) -> Option<Ordering> {
489 /// self.height.partial_cmp(&other.height)
493 /// impl PartialEq for Person {
494 /// fn eq(&self, other: &Person) -> bool {
495 /// self.height == other.height
506 /// assert_eq!(x < y, true);
507 /// assert_eq!(x.lt(&y), true);
510 #[stable(feature = "rust1", since = "1.0.0")]
511 pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
512 /// This method returns an ordering between `self` and `other` values if one exists.
517 /// use std::cmp::Ordering;
519 /// let result = 1.0.partial_cmp(&2.0);
520 /// assert_eq!(result, Some(Ordering::Less));
522 /// let result = 1.0.partial_cmp(&1.0);
523 /// assert_eq!(result, Some(Ordering::Equal));
525 /// let result = 2.0.partial_cmp(&1.0);
526 /// assert_eq!(result, Some(Ordering::Greater));
529 /// When comparison is impossible:
532 /// let result = std::f64::NAN.partial_cmp(&1.0);
533 /// assert_eq!(result, None);
535 #[stable(feature = "rust1", since = "1.0.0")]
536 fn partial_cmp(&self, other: &Rhs) -> Option<Ordering>;
538 /// This method tests less than (for `self` and `other`) and is used by the `<` operator.
543 /// let result = 1.0 < 2.0;
544 /// assert_eq!(result, true);
546 /// let result = 2.0 < 1.0;
547 /// assert_eq!(result, false);
550 #[stable(feature = "rust1", since = "1.0.0")]
551 fn lt(&self, other: &Rhs) -> bool {
552 match self.partial_cmp(other) {
558 /// This method tests less than or equal to (for `self` and `other`) and is used by the `<=`
564 /// let result = 1.0 <= 2.0;
565 /// assert_eq!(result, true);
567 /// let result = 2.0 <= 2.0;
568 /// assert_eq!(result, true);
571 #[stable(feature = "rust1", since = "1.0.0")]
572 fn le(&self, other: &Rhs) -> bool {
573 match self.partial_cmp(other) {
574 Some(Less) | Some(Equal) => true,
579 /// This method tests greater than (for `self` and `other`) and is used by the `>` operator.
584 /// let result = 1.0 > 2.0;
585 /// assert_eq!(result, false);
587 /// let result = 2.0 > 2.0;
588 /// assert_eq!(result, false);
591 #[stable(feature = "rust1", since = "1.0.0")]
592 fn gt(&self, other: &Rhs) -> bool {
593 match self.partial_cmp(other) {
594 Some(Greater) => true,
599 /// This method tests greater than or equal to (for `self` and `other`) and is used by the `>=`
605 /// let result = 2.0 >= 1.0;
606 /// assert_eq!(result, true);
608 /// let result = 2.0 >= 2.0;
609 /// assert_eq!(result, true);
612 #[stable(feature = "rust1", since = "1.0.0")]
613 fn ge(&self, other: &Rhs) -> bool {
614 match self.partial_cmp(other) {
615 Some(Greater) | Some(Equal) => true,
621 /// Compare and return the minimum of two values.
623 /// Returns the first argument if the comparison determines them to be equal.
630 /// assert_eq!(1, cmp::min(1, 2));
631 /// assert_eq!(2, cmp::min(2, 2));
634 #[stable(feature = "rust1", since = "1.0.0")]
635 pub fn min<T: Ord>(v1: T, v2: T) -> T {
636 if v1 <= v2 { v1 } else { v2 }
639 /// Compare and return the maximum of two values.
641 /// Returns the second argument if the comparison determines them to be equal.
648 /// assert_eq!(2, cmp::max(1, 2));
649 /// assert_eq!(2, cmp::max(2, 2));
652 #[stable(feature = "rust1", since = "1.0.0")]
653 pub fn max<T: Ord>(v1: T, v2: T) -> T {
654 if v2 >= v1 { v2 } else { v1 }
657 // Implementation of PartialEq, Eq, PartialOrd and Ord for primitive types
659 use cmp::Ordering::{self, Less, Greater, Equal};
661 macro_rules! partial_eq_impl {
663 #[stable(feature = "rust1", since = "1.0.0")]
664 impl PartialEq for $t {
666 fn eq(&self, other: &$t) -> bool { (*self) == (*other) }
668 fn ne(&self, other: &$t) -> bool { (*self) != (*other) }
673 #[stable(feature = "rust1", since = "1.0.0")]
674 impl PartialEq for () {
676 fn eq(&self, _other: &()) -> bool { true }
678 fn ne(&self, _other: &()) -> bool { false }
682 bool char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64
685 macro_rules! eq_impl {
687 #[stable(feature = "rust1", since = "1.0.0")]
692 eq_impl! { () bool char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
694 macro_rules! partial_ord_impl {
696 #[stable(feature = "rust1", since = "1.0.0")]
697 impl PartialOrd for $t {
699 fn partial_cmp(&self, other: &$t) -> Option<Ordering> {
700 match (self <= other, self >= other) {
701 (false, false) => None,
702 (false, true) => Some(Greater),
703 (true, false) => Some(Less),
704 (true, true) => Some(Equal),
708 fn lt(&self, other: &$t) -> bool { (*self) < (*other) }
710 fn le(&self, other: &$t) -> bool { (*self) <= (*other) }
712 fn ge(&self, other: &$t) -> bool { (*self) >= (*other) }
714 fn gt(&self, other: &$t) -> bool { (*self) > (*other) }
719 #[stable(feature = "rust1", since = "1.0.0")]
720 impl PartialOrd for () {
722 fn partial_cmp(&self, _: &()) -> Option<Ordering> {
727 #[stable(feature = "rust1", since = "1.0.0")]
728 impl PartialOrd for bool {
730 fn partial_cmp(&self, other: &bool) -> Option<Ordering> {
731 (*self as u8).partial_cmp(&(*other as u8))
735 partial_ord_impl! { f32 f64 }
737 macro_rules! ord_impl {
739 #[stable(feature = "rust1", since = "1.0.0")]
740 impl PartialOrd for $t {
742 fn partial_cmp(&self, other: &$t) -> Option<Ordering> {
743 Some(self.cmp(other))
746 fn lt(&self, other: &$t) -> bool { (*self) < (*other) }
748 fn le(&self, other: &$t) -> bool { (*self) <= (*other) }
750 fn ge(&self, other: &$t) -> bool { (*self) >= (*other) }
752 fn gt(&self, other: &$t) -> bool { (*self) > (*other) }
755 #[stable(feature = "rust1", since = "1.0.0")]
758 fn cmp(&self, other: &$t) -> Ordering {
759 if *self == *other { Equal }
760 else if *self < *other { Less }
767 #[stable(feature = "rust1", since = "1.0.0")]
770 fn cmp(&self, _other: &()) -> Ordering { Equal }
773 #[stable(feature = "rust1", since = "1.0.0")]
776 fn cmp(&self, other: &bool) -> Ordering {
777 (*self as u8).cmp(&(*other as u8))
781 ord_impl! { char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
783 #[unstable(feature = "never_type_impls", issue = "35121")]
784 impl PartialEq for ! {
785 fn eq(&self, _: &!) -> bool {
790 #[unstable(feature = "never_type_impls", issue = "35121")]
793 #[unstable(feature = "never_type_impls", issue = "35121")]
794 impl PartialOrd for ! {
795 fn partial_cmp(&self, _: &!) -> Option<Ordering> {
800 #[unstable(feature = "never_type_impls", issue = "35121")]
802 fn cmp(&self, _: &!) -> Ordering {
809 #[stable(feature = "rust1", since = "1.0.0")]
810 impl<'a, 'b, A: ?Sized, B: ?Sized> PartialEq<&'b B> for &'a A where A: PartialEq<B> {
812 fn eq(&self, other: & &'b B) -> bool { PartialEq::eq(*self, *other) }
814 fn ne(&self, other: & &'b B) -> bool { PartialEq::ne(*self, *other) }
816 #[stable(feature = "rust1", since = "1.0.0")]
817 impl<'a, 'b, A: ?Sized, B: ?Sized> PartialOrd<&'b B> for &'a A where A: PartialOrd<B> {
819 fn partial_cmp(&self, other: &&'b B) -> Option<Ordering> {
820 PartialOrd::partial_cmp(*self, *other)
823 fn lt(&self, other: & &'b B) -> bool { PartialOrd::lt(*self, *other) }
825 fn le(&self, other: & &'b B) -> bool { PartialOrd::le(*self, *other) }
827 fn ge(&self, other: & &'b B) -> bool { PartialOrd::ge(*self, *other) }
829 fn gt(&self, other: & &'b B) -> bool { PartialOrd::gt(*self, *other) }
831 #[stable(feature = "rust1", since = "1.0.0")]
832 impl<'a, A: ?Sized> Ord for &'a A where A: Ord {
834 fn cmp(&self, other: & &'a A) -> Ordering { Ord::cmp(*self, *other) }
836 #[stable(feature = "rust1", since = "1.0.0")]
837 impl<'a, A: ?Sized> Eq for &'a A where A: Eq {}
841 #[stable(feature = "rust1", since = "1.0.0")]
842 impl<'a, 'b, A: ?Sized, B: ?Sized> PartialEq<&'b mut B> for &'a mut A where A: PartialEq<B> {
844 fn eq(&self, other: &&'b mut B) -> bool { PartialEq::eq(*self, *other) }
846 fn ne(&self, other: &&'b mut B) -> bool { PartialEq::ne(*self, *other) }
848 #[stable(feature = "rust1", since = "1.0.0")]
849 impl<'a, 'b, A: ?Sized, B: ?Sized> PartialOrd<&'b mut B> for &'a mut A where A: PartialOrd<B> {
851 fn partial_cmp(&self, other: &&'b mut B) -> Option<Ordering> {
852 PartialOrd::partial_cmp(*self, *other)
855 fn lt(&self, other: &&'b mut B) -> bool { PartialOrd::lt(*self, *other) }
857 fn le(&self, other: &&'b mut B) -> bool { PartialOrd::le(*self, *other) }
859 fn ge(&self, other: &&'b mut B) -> bool { PartialOrd::ge(*self, *other) }
861 fn gt(&self, other: &&'b mut B) -> bool { PartialOrd::gt(*self, *other) }
863 #[stable(feature = "rust1", since = "1.0.0")]
864 impl<'a, A: ?Sized> Ord for &'a mut A where A: Ord {
866 fn cmp(&self, other: &&'a mut A) -> Ordering { Ord::cmp(*self, *other) }
868 #[stable(feature = "rust1", since = "1.0.0")]
869 impl<'a, A: ?Sized> Eq for &'a mut A where A: Eq {}
871 #[stable(feature = "rust1", since = "1.0.0")]
872 impl<'a, 'b, A: ?Sized, B: ?Sized> PartialEq<&'b mut B> for &'a A where A: PartialEq<B> {
874 fn eq(&self, other: &&'b mut B) -> bool { PartialEq::eq(*self, *other) }
876 fn ne(&self, other: &&'b mut B) -> bool { PartialEq::ne(*self, *other) }
879 #[stable(feature = "rust1", since = "1.0.0")]
880 impl<'a, 'b, A: ?Sized, B: ?Sized> PartialEq<&'b B> for &'a mut A where A: PartialEq<B> {
882 fn eq(&self, other: &&'b B) -> bool { PartialEq::eq(*self, *other) }
884 fn ne(&self, other: &&'b B) -> bool { PartialEq::ne(*self, *other) }