ptr: split out borrowed pointer utilities
The ptr module is intended to be for raw pointers. Closes #3111
This commit is contained in:
parent
077ca79941
commit
454133127a
8 changed files with 72 additions and 53 deletions
|
@ -255,18 +255,6 @@ pub fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
|
|||
thing as *mut T
|
||||
}
|
||||
|
||||
/// Cast a region pointer - &T - to a uint.
|
||||
#[inline(always)]
|
||||
pub fn to_uint<T>(thing: &T) -> uint {
|
||||
thing as *T as uint
|
||||
}
|
||||
|
||||
/// Determine if two borrowed pointers point to the same thing.
|
||||
#[inline(always)]
|
||||
pub fn ref_eq<'a,'b,T>(thing: &'a T, other: &'b T) -> bool {
|
||||
to_uint(thing) == to_uint(other)
|
||||
}
|
||||
|
||||
/**
|
||||
Given a **T (pointer to an array of pointers),
|
||||
iterate through each *T, up to the provided `len`,
|
||||
|
@ -411,40 +399,6 @@ impl<T> Ord for *const T {
|
|||
}
|
||||
}
|
||||
|
||||
// Equality for region pointers
|
||||
#[cfg(not(test))]
|
||||
impl<'self,T:Eq> Eq for &'self T {
|
||||
#[inline(always)]
|
||||
fn eq(&self, other: & &'self T) -> bool {
|
||||
*(*self) == *(*other)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn ne(&self, other: & &'self T) -> bool {
|
||||
*(*self) != *(*other)
|
||||
}
|
||||
}
|
||||
|
||||
// Comparison for region pointers
|
||||
#[cfg(not(test))]
|
||||
impl<'self,T:Ord> Ord for &'self T {
|
||||
#[inline(always)]
|
||||
fn lt(&self, other: & &'self T) -> bool {
|
||||
*(*self) < *(*other)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn le(&self, other: & &'self T) -> bool {
|
||||
*(*self) <= *(*other)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn ge(&self, other: & &'self T) -> bool {
|
||||
*(*self) >= *(*other)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn gt(&self, other: & &'self T) -> bool {
|
||||
*(*self) > *(*other)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod ptr_tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue