@@ -2060,6 +2060,12 @@ pub trait MutableVector<'a, T> {
2060
2060
*/
2061
2061
unsafe fn init_elem ( self , i : uint , val : T ) ;
2062
2062
2063
+ /// Copies data from `src` to `self`
2064
+ ///
2065
+ /// `self` and `src` must not overlap. Fails if `self` is
2066
+ /// shorter than `src`.
2067
+ unsafe fn copy_memory ( self , src : & [ T ] ) ;
2068
+
2063
2069
/// Similar to `as_imm_buf` but passing a `*mut T`
2064
2070
fn as_mut_buf < U > ( self , f : |* mut T , uint| -> U ) -> U ;
2065
2071
}
@@ -2197,6 +2203,16 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] {
2197
2203
} )
2198
2204
}
2199
2205
2206
+ #[ inline]
2207
+ unsafe fn copy_memory ( self , src : & [ T ] ) {
2208
+ self . as_mut_buf ( |p_dst, len_dst| {
2209
+ src. as_imm_buf ( |p_src, len_src| {
2210
+ assert ! ( len_dst >= len_src)
2211
+ ptr:: copy_memory ( p_dst, p_src, len_src)
2212
+ } )
2213
+ } )
2214
+ }
2215
+
2200
2216
#[ inline]
2201
2217
fn as_mut_buf < U > ( self , f : |* mut T , uint| -> U ) -> U {
2202
2218
let Slice { data, len } = self . repr ( ) ;
@@ -2238,7 +2254,7 @@ pub unsafe fn from_buf<T>(ptr: *T, elts: uint) -> ~[T] {
2238
2254
pub mod raw {
2239
2255
use cast;
2240
2256
use ptr;
2241
- use vec:: { with_capacity, ImmutableVector , MutableVector } ;
2257
+ use vec:: { with_capacity, MutableVector } ;
2242
2258
use unstable:: raw:: Slice ;
2243
2259
2244
2260
/**
@@ -2288,21 +2304,6 @@ pub mod raw {
2288
2304
dst
2289
2305
}
2290
2306
2291
- /**
2292
- * Copies data from one vector to another.
2293
- *
2294
- * Copies `src` to `dst`. The source and destination may overlap.
2295
- */
2296
- #[ inline]
2297
- pub unsafe fn copy_memory < T > ( dst : & mut [ T ] , src : & [ T ] ) {
2298
- dst. as_mut_buf ( |p_dst, len_dst| {
2299
- src. as_imm_buf ( |p_src, len_src| {
2300
- assert ! ( len_dst >= len_src)
2301
- ptr:: copy_memory ( p_dst, p_src, len_src)
2302
- } )
2303
- } )
2304
- }
2305
-
2306
2307
/**
2307
2308
* Returns a pointer to first element in slice and adjusts
2308
2309
* slice so it no longer contains that element. Fails if
@@ -2331,7 +2332,7 @@ pub mod raw {
2331
2332
2332
2333
/// Operations on `[u8]`.
2333
2334
pub mod bytes {
2334
- use vec:: raw ;
2335
+ use vec:: MutableVector ;
2335
2336
use ptr;
2336
2337
2337
2338
/// A trait for operations on mutable `[u8]`s.
@@ -2358,8 +2359,8 @@ pub mod bytes {
2358
2359
*/
2359
2360
#[ inline]
2360
2361
pub fn copy_memory ( dst : & mut [ u8 ] , src : & [ u8 ] ) {
2361
- // Bound checks are done at vec::raw:: copy_memory.
2362
- unsafe { raw :: copy_memory ( dst , src) }
2362
+ // Bound checks are done at . copy_memory.
2363
+ unsafe { dst . copy_memory ( src) }
2363
2364
}
2364
2365
2365
2366
/**
@@ -3585,7 +3586,7 @@ mod tests {
3585
3586
unsafe {
3586
3587
let mut a = [ 1 , 2 , 3 , 4 ] ;
3587
3588
let b = [ 1 , 2 , 3 , 4 , 5 ] ;
3588
- raw :: copy_memory ( a , b) ;
3589
+ a . copy_memory ( b) ;
3589
3590
}
3590
3591
}
3591
3592
0 commit comments