From 3cc730e1e18c3b678e811bfbd51450201e538c75 Mon Sep 17 00:00:00 2001 From: Mike Pedersen Date: Fri, 12 Dec 2014 18:44:22 +0100 Subject: [PATCH] Add Ord impl to raw pointers --- src/libcore/ptr.rs | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 5c61a1ed103..edd5f989797 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -93,7 +93,7 @@ use intrinsics; use option::Option; use option::Option::{Some, None}; -use cmp::{PartialEq, Eq, PartialOrd, Equiv}; +use cmp::{PartialEq, Eq, Ord, PartialOrd, Equiv}; use cmp::Ordering; use cmp::Ordering::{Less, Equal, Greater}; @@ -388,16 +388,23 @@ mod externfnpointers { } // Comparison for pointers +impl Ord for *const T { + #[inline] + fn cmp(&self, other: &*const T) -> Ordering { + if self < other { + Less + } else if self == other { + Equal + } else { + Greater + } + } +} + impl PartialOrd for *const T { #[inline] fn partial_cmp(&self, other: &*const T) -> Option { - if self < other { - Some(Less) - } else if self == other { - Some(Equal) - } else { - Some(Greater) - } + Some(self.cmp(other)) } #[inline] @@ -413,16 +420,23 @@ impl PartialOrd for *const T { fn ge(&self, other: &*const T) -> bool { *self >= *other } } +impl Ord for *mut T { + #[inline] + fn cmp(&self, other: &*mut T) -> Ordering { + if self < other { + Less + } else if self == other { + Equal + } else { + Greater + } + } +} + impl PartialOrd for *mut T { #[inline] fn partial_cmp(&self, other: &*mut T) -> Option { - if self < other { - Some(Less) - } else if self == other { - Some(Equal) - } else { - Some(Greater) - } + Some(self.cmp(other)) } #[inline]