about summary refs log tree commit diff
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2013-12-16 23:30:56 +1100
committerHuon Wilson <dbau.pp+github@gmail.com>2013-12-17 08:35:34 +1100
commitad20a78c548819b6671ee11eed7501e61429575a (patch)
tree752819f81a71b6cafcaea671d1cb4a3ec5d32616
parent33b6bf4bc1456b670e134b7581d2e26b8c2cff6c (diff)
downloadrust-ad20a78c548819b6671ee11eed7501e61429575a.tar.gz
rust-ad20a78c548819b6671ee11eed7501e61429575a.zip
std::vec::raw: convert init_elem to a method.
-rw-r--r--src/libstd/vec.rs32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs
index 404cc66a2d2..3a2b7c68955 100644
--- a/src/libstd/vec.rs
+++ b/src/libstd/vec.rs
@@ -2053,6 +2053,13 @@ pub trait MutableVector<'a, T> {
     /// Unsafely sets the element in index to the value
     unsafe fn unsafe_set(self, index: uint, val: T);
 
+    /**
+     * Unchecked vector index assignment.  Does not drop the
+     * old value and hence is only suitable when the vector
+     * is newly allocated.
+     */
+    unsafe fn init_elem(self, i: uint, val: T);
+
     /// Similar to `as_imm_buf` but passing a `*mut T`
     fn as_mut_buf<U>(self, f: |*mut T, uint| -> U) -> U;
 }
@@ -2182,6 +2189,15 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] {
     }
 
     #[inline]
+    unsafe fn init_elem(self, i: uint, val: T) {
+        let mut alloc = Some(val);
+        self.as_mut_buf(|p, _len| {
+            intrinsics::move_val_init(&mut(*ptr::mut_offset(p, i as int)),
+                                      alloc.take_unwrap());
+        })
+    }
+
+    #[inline]
     fn as_mut_buf<U>(self, f: |*mut T, uint| -> U) -> U {
         let Slice{ data, len } = self.repr();
         f(data as *mut T, len)
@@ -2221,9 +2237,7 @@ pub unsafe fn from_buf<T>(ptr: *T, elts: uint) -> ~[T] {
 /// Unsafe operations
 pub mod raw {
     use cast;
-    use option::Some;
     use ptr;
-    use unstable::intrinsics;
     use vec::{with_capacity, ImmutableVector, MutableVector};
     use unstable::raw::Slice;
 
@@ -2258,20 +2272,6 @@ pub mod raw {
     }
 
     /**
-     * Unchecked vector index assignment.  Does not drop the
-     * old value and hence is only suitable when the vector
-     * is newly allocated.
-     */
-    #[inline]
-    pub unsafe fn init_elem<T>(v: &mut [T], i: uint, val: T) {
-        let mut alloc = Some(val);
-        v.as_mut_buf(|p, _len| {
-            intrinsics::move_val_init(&mut(*ptr::mut_offset(p, i as int)),
-                                      alloc.take_unwrap());
-        })
-    }
-
-    /**
     * Constructs a vector from an unsafe pointer to a buffer
     *
     * # Arguments