]> git.lizzy.rs Git - rust.git/blobdiff - src/libstd/ptr.rs
use TotalEq for HashMap
[rust.git] / src / libstd / ptr.rs
index 037984d9e7fc775d1948f38976431fcd411551ef..504c613bf4c1763e4e7f15eb53895b37df395c67 100644 (file)
@@ -17,9 +17,9 @@
 use iter::{range, Iterator};
 use mem;
 use option::{Option, Some, None};
-use unstable::intrinsics;
+use intrinsics;
 
-#[cfg(not(test))] use cmp::{Eq, Ord};
+#[cfg(not(test))] use cmp::{Eq, TotalEq, Ord};
 
 /// Return the offset of the first null pointer in `buf`.
 #[inline]
@@ -163,7 +163,6 @@ pub unsafe fn read_and_zero<T>(dest: *mut T) -> T {
   SAFETY NOTE: Pointer-arithmetic. Dragons be here.
 */
 pub unsafe fn array_each_with_len<T>(arr: **T, len: uint, cb: |*T|) {
-    debug!("array_each_with_len: before iterate");
     if arr.is_null() {
         fail!("ptr::array_each_with_len failure: arr input is null pointer");
     }
@@ -172,7 +171,6 @@ pub unsafe fn array_each_with_len<T>(arr: **T, len: uint, cb: |*T|) {
         let n = arr.offset(e as int);
         cb(*n);
     }
-    debug!("array_each_with_len: after iterate");
 }
 
 /**
@@ -189,7 +187,6 @@ pub unsafe fn array_each<T>(arr: **T, cb: |*T|) {
         fail!("ptr::array_each_with_len failure: arr input is null pointer");
     }
     let len = buf_len(arr);
-    debug!("array_each inferred len: {}", len);
     array_each_with_len(arr, len, cb);
 }
 
@@ -213,7 +210,8 @@ fn is_not_null(&self) -> bool { !self.is_null() }
     /// be pointing to invalid memory.
     unsafe fn to_option(&self) -> Option<&T>;
     /// Calculates the offset from a pointer. The offset *must* be in-bounds of
-    /// the object, or one-byte-past-the-end.
+    /// the object, or one-byte-past-the-end.  `count` is in units of T; e.g. a
+    /// `count` of 3 represents a pointer offset of `3 * sizeof::<T>()` bytes.
     unsafe fn offset(self, count: int) -> Self;
 }
 
@@ -274,6 +272,9 @@ fn eq(&self, other: &*T) -> bool {
     fn ne(&self, other: &*T) -> bool { !self.eq(other) }
 }
 
+#[cfg(not(test))]
+impl<T> TotalEq for *T {}
+
 #[cfg(not(test))]
 impl<T> Eq for *mut T {
     #[inline]
@@ -284,6 +285,9 @@ fn eq(&self, other: &*mut T) -> bool {
     fn ne(&self, other: &*mut T) -> bool { !self.eq(other) }
 }
 
+#[cfg(not(test))]
+impl<T> TotalEq for *mut T {}
+
 // Equivalence for pointers
 #[cfg(not(test))]
 impl<T> Equiv<*mut T> for *T {
@@ -390,7 +394,7 @@ pub mod ptr_tests {
     use cast;
     use libc;
     use str;
-    use vec::{ImmutableVector, MutableVector};
+    use slice::{ImmutableVector, MutableVector};
 
     #[test]
     fn test() {
@@ -635,6 +639,6 @@ fn test_set_memory() {
         let mut xs = [0u8, ..20];
         let ptr = xs.as_mut_ptr();
         unsafe { set_memory(ptr, 5u8, xs.len()); }
-        assert_eq!(xs, [5u8, ..20]);
+        assert!(xs == [5u8, ..20]);
     }
 }