@@ -2060,6 +2060,12 @@ pub trait MutableVector<'a, T> {
20602060 */
20612061 unsafe fn init_elem ( self , i : uint , val : T ) ;
20622062
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+
20632069 /// Similar to `as_imm_buf` but passing a `*mut T`
20642070 fn as_mut_buf < U > ( self , f : |* mut T , uint| -> U ) -> U ;
20652071}
@@ -2197,6 +2203,16 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] {
21972203 } )
21982204 }
21992205
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+
22002216 #[ inline]
22012217 fn as_mut_buf < U > ( self , f : |* mut T , uint| -> U ) -> U {
22022218 let Slice { data, len } = self . repr ( ) ;
@@ -2238,7 +2254,7 @@ pub unsafe fn from_buf<T>(ptr: *T, elts: uint) -> ~[T] {
22382254pub mod raw {
22392255 use cast;
22402256 use ptr;
2241- use vec:: { with_capacity, ImmutableVector , MutableVector } ;
2257+ use vec:: { with_capacity, MutableVector } ;
22422258 use unstable:: raw:: Slice ;
22432259
22442260 /**
@@ -2288,21 +2304,6 @@ pub mod raw {
22882304 dst
22892305 }
22902306
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-
23062307 /**
23072308 * Returns a pointer to first element in slice and adjusts
23082309 * slice so it no longer contains that element. Fails if
@@ -2331,7 +2332,7 @@ pub mod raw {
23312332
23322333/// Operations on `[u8]`.
23332334pub mod bytes {
2334- use vec:: raw ;
2335+ use vec:: MutableVector ;
23352336 use ptr;
23362337
23372338 /// A trait for operations on mutable `[u8]`s.
@@ -2358,8 +2359,8 @@ pub mod bytes {
23582359 */
23592360 #[ inline]
23602361 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) }
23632364 }
23642365
23652366 /**
@@ -3585,7 +3586,7 @@ mod tests {
35853586 unsafe {
35863587 let mut a = [ 1 , 2 , 3 , 4 ] ;
35873588 let b = [ 1 , 2 , 3 , 4 , 5 ] ;
3588- raw :: copy_memory ( a , b) ;
3589+ a . copy_memory ( b) ;
35893590 }
35903591 }
35913592
0 commit comments