@@ -2053,6 +2053,13 @@ pub trait MutableVector<'a, T> {
20532053 /// Unsafely sets the element in index to the value
20542054 unsafe fn unsafe_set ( self , index : uint , val : T ) ;
20552055
2056+ /**
2057+ * Unchecked vector index assignment. Does not drop the
2058+ * old value and hence is only suitable when the vector
2059+ * is newly allocated.
2060+ */
2061+ unsafe fn init_elem ( self , i : uint , val : T ) ;
2062+
20562063 /// Similar to `as_imm_buf` but passing a `*mut T`
20572064 fn as_mut_buf < U > ( self , f : |* mut T , uint| -> U ) -> U ;
20582065}
@@ -2181,6 +2188,15 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] {
21812188 * self . unsafe_mut_ref ( index) = val;
21822189 }
21832190
2191+ #[ inline]
2192+ unsafe fn init_elem ( self , i : uint , val : T ) {
2193+ let mut alloc = Some ( val) ;
2194+ self . as_mut_buf ( |p, _len| {
2195+ intrinsics:: move_val_init ( & mut ( * ptr:: mut_offset ( p, i as int ) ) ,
2196+ alloc. take_unwrap ( ) ) ;
2197+ } )
2198+ }
2199+
21842200 #[ inline]
21852201 fn as_mut_buf < U > ( self , f : |* mut T , uint| -> U ) -> U {
21862202 let Slice { data, len } = self . repr ( ) ;
@@ -2221,9 +2237,7 @@ pub unsafe fn from_buf<T>(ptr: *T, elts: uint) -> ~[T] {
22212237/// Unsafe operations
22222238pub mod raw {
22232239 use cast;
2224- use option:: Some ;
22252240 use ptr;
2226- use unstable:: intrinsics;
22272241 use vec:: { with_capacity, ImmutableVector , MutableVector } ;
22282242 use unstable:: raw:: Slice ;
22292243
@@ -2257,20 +2271,6 @@ pub mod raw {
22572271 } ) )
22582272 }
22592273
2260- /**
2261- * Unchecked vector index assignment. Does not drop the
2262- * old value and hence is only suitable when the vector
2263- * is newly allocated.
2264- */
2265- #[ inline]
2266- pub unsafe fn init_elem < T > ( v : & mut [ T ] , i : uint , val : T ) {
2267- let mut alloc = Some ( val) ;
2268- v. as_mut_buf ( |p, _len| {
2269- intrinsics:: move_val_init ( & mut ( * ptr:: mut_offset ( p, i as int ) ) ,
2270- alloc. take_unwrap ( ) ) ;
2271- } )
2272- }
2273-
22742274 /**
22752275 * Constructs a vector from an unsafe pointer to a buffer
22762276 *
0 commit comments