]> git.lizzy.rs Git - rust.git/commitdiff
std::vec::raw: convert init_elem to a method.
authorHuon Wilson <dbau.pp+github@gmail.com>
Mon, 16 Dec 2013 12:30:56 +0000 (23:30 +1100)
committerHuon Wilson <dbau.pp+github@gmail.com>
Mon, 16 Dec 2013 21:35:34 +0000 (08:35 +1100)
src/libstd/vec.rs

index 404cc66a2d267e5854f872d8fb8e878640830785..3a2b7c689552d9751c28ab11e0637432546566c8 100644 (file)
@@ -2053,6 +2053,13 @@ fn mut_split_at(self, mid: uint) -> (&'a mut [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;
 }
@@ -2181,6 +2188,15 @@ unsafe fn unsafe_set(self, index: uint, val: T) {
         *self.unsafe_mut_ref(index) = val;
     }
 
+    #[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();
@@ -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;
 
@@ -2257,20 +2271,6 @@ pub unsafe fn mut_buf_as_slice<T,
         }))
     }
 
-    /**
-     * 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
     *