|
| 1 | +// Copyright 2012-2013 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 | +//! Borrowed pointer utilities |
| 12 | +
|
| 13 | +#[cfg(not(test))] |
| 14 | +use prelude::*; |
| 15 | + |
| 16 | +/// Cast a region pointer - &T - to a uint. |
| 17 | +#[inline(always)] |
| 18 | +pub fn to_uint<T>(thing: &T) -> uint { |
| 19 | + thing as *T as uint |
| 20 | +} |
| 21 | + |
| 22 | +/// Determine if two borrowed pointers point to the same thing. |
| 23 | +#[inline(always)] |
| 24 | +pub fn ref_eq<'a, 'b, T>(thing: &'a T, other: &'b T) -> bool { |
| 25 | + to_uint(thing) == to_uint(other) |
| 26 | +} |
| 27 | + |
| 28 | +// Equality for region pointers |
| 29 | +#[cfg(not(test))] |
| 30 | +impl<'self, T: Eq> Eq for &'self T { |
| 31 | + #[inline(always)] |
| 32 | + fn eq(&self, other: & &'self T) -> bool { |
| 33 | + *(*self) == *(*other) |
| 34 | + } |
| 35 | + #[inline(always)] |
| 36 | + fn ne(&self, other: & &'self T) -> bool { |
| 37 | + *(*self) != *(*other) |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +// Comparison for region pointers |
| 42 | +#[cfg(not(test))] |
| 43 | +impl<'self, T: Ord> Ord for &'self T { |
| 44 | + #[inline(always)] |
| 45 | + fn lt(&self, other: & &'self T) -> bool { |
| 46 | + *(*self) < *(*other) |
| 47 | + } |
| 48 | + #[inline(always)] |
| 49 | + fn le(&self, other: & &'self T) -> bool { |
| 50 | + *(*self) <= *(*other) |
| 51 | + } |
| 52 | + #[inline(always)] |
| 53 | + fn ge(&self, other: & &'self T) -> bool { |
| 54 | + *(*self) >= *(*other) |
| 55 | + } |
| 56 | + #[inline(always)] |
| 57 | + fn gt(&self, other: & &'self T) -> bool { |
| 58 | + *(*self) > *(*other) |
| 59 | + } |
| 60 | +} |
0 commit comments