Add Ord impl to raw pointers
This commit is contained in:
parent
a5921241a3
commit
3cc730e1e1
1 changed files with 29 additions and 15 deletions
|
@ -93,7 +93,7 @@ use intrinsics;
|
||||||
use option::Option;
|
use option::Option;
|
||||||
use option::Option::{Some, None};
|
use option::Option::{Some, None};
|
||||||
|
|
||||||
use cmp::{PartialEq, Eq, PartialOrd, Equiv};
|
use cmp::{PartialEq, Eq, Ord, PartialOrd, Equiv};
|
||||||
use cmp::Ordering;
|
use cmp::Ordering;
|
||||||
use cmp::Ordering::{Less, Equal, Greater};
|
use cmp::Ordering::{Less, Equal, Greater};
|
||||||
|
|
||||||
|
@ -388,16 +388,23 @@ mod externfnpointers {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comparison for pointers
|
// Comparison for pointers
|
||||||
|
impl<T> Ord for *const T {
|
||||||
|
#[inline]
|
||||||
|
fn cmp(&self, other: &*const T) -> Ordering {
|
||||||
|
if self < other {
|
||||||
|
Less
|
||||||
|
} else if self == other {
|
||||||
|
Equal
|
||||||
|
} else {
|
||||||
|
Greater
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> PartialOrd for *const T {
|
impl<T> PartialOrd for *const T {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn partial_cmp(&self, other: &*const T) -> Option<Ordering> {
|
fn partial_cmp(&self, other: &*const T) -> Option<Ordering> {
|
||||||
if self < other {
|
Some(self.cmp(other))
|
||||||
Some(Less)
|
|
||||||
} else if self == other {
|
|
||||||
Some(Equal)
|
|
||||||
} else {
|
|
||||||
Some(Greater)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -413,16 +420,23 @@ impl<T> PartialOrd for *const T {
|
||||||
fn ge(&self, other: &*const T) -> bool { *self >= *other }
|
fn ge(&self, other: &*const T) -> bool { *self >= *other }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> Ord for *mut T {
|
||||||
|
#[inline]
|
||||||
|
fn cmp(&self, other: &*mut T) -> Ordering {
|
||||||
|
if self < other {
|
||||||
|
Less
|
||||||
|
} else if self == other {
|
||||||
|
Equal
|
||||||
|
} else {
|
||||||
|
Greater
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> PartialOrd for *mut T {
|
impl<T> PartialOrd for *mut T {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn partial_cmp(&self, other: &*mut T) -> Option<Ordering> {
|
fn partial_cmp(&self, other: &*mut T) -> Option<Ordering> {
|
||||||
if self < other {
|
Some(self.cmp(other))
|
||||||
Some(Less)
|
|
||||||
} else if self == other {
|
|
||||||
Some(Equal)
|
|
||||||
} else {
|
|
||||||
Some(Greater)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue