about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2013-03-09 19:14:35 -0800
committerBrian Anderson <banderson@mozilla.com>2013-03-11 13:44:32 -0700
commitc88ce30c485b8df5f6dfa55d216c19c10cafe5dd (patch)
tree59a238cdd4eddbbf50f56acc5d49379ac4899f4b /src
parentce24ebb8589cb6533359b0e398e6da88e9c228ef (diff)
downloadrust-c88ce30c485b8df5f6dfa55d216c19c10cafe5dd.tar.gz
rust-c88ce30c485b8df5f6dfa55d216c19c10cafe5dd.zip
core: Add vec::raw::mut_buf_as_slice
Diffstat (limited to 'src')
-rw-r--r--src/libcore/vec.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs
index aed98f3573e..697bfe63b18 100644
--- a/src/libcore/vec.rs
+++ b/src/libcore/vec.rs
@@ -2146,6 +2146,20 @@ pub mod raw {
     }
 
     /**
+     * Form a slice from a pointer and length (as a number of units,
+     * not bytes).
+     */
+    #[inline(always)]
+    pub unsafe fn mut_buf_as_slice<T,U>(p: *mut T,
+                                        len: uint,
+                                        f: &fn(v: &mut [T]) -> U) -> U {
+        let pair = (p, len * sys::nonzero_size_of::<T>());
+        let v : *(&blk/mut [T]) =
+            ::cast::reinterpret_cast(&addr_of(&pair));
+        f(*v)
+    }
+
+    /**
      * Unchecked vector indexing.
      */
     #[inline(always)]