about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
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)]