@@ -2053,6 +2053,13 @@ pub trait MutableVector<'a, T> {
2053
2053
/// Unsafely sets the element in index to the value
2054
2054
unsafe fn unsafe_set ( self , index : uint , val : T ) ;
2055
2055
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
+
2056
2063
/// Similar to `as_imm_buf` but passing a `*mut T`
2057
2064
fn as_mut_buf < U > ( self , f : |* mut T , uint| -> U ) -> U ;
2058
2065
}
@@ -2181,6 +2188,15 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] {
2181
2188
* self . unsafe_mut_ref ( index) = val;
2182
2189
}
2183
2190
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
+
2184
2200
#[ inline]
2185
2201
fn as_mut_buf < U > ( self , f : |* mut T , uint| -> U ) -> U {
2186
2202
let Slice { data, len } = self . repr ( ) ;
@@ -2221,9 +2237,7 @@ pub unsafe fn from_buf<T>(ptr: *T, elts: uint) -> ~[T] {
2221
2237
/// Unsafe operations
2222
2238
pub mod raw {
2223
2239
use cast;
2224
- use option:: Some ;
2225
2240
use ptr;
2226
- use unstable:: intrinsics;
2227
2241
use vec:: { with_capacity, ImmutableVector , MutableVector } ;
2228
2242
use unstable:: raw:: Slice ;
2229
2243
@@ -2257,20 +2271,6 @@ pub mod raw {
2257
2271
} ) )
2258
2272
}
2259
2273
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
-
2274
2274
/**
2275
2275
* Constructs a vector from an unsafe pointer to a buffer
2276
2276
*
0 commit comments