@@ -48,7 +48,7 @@ use result::Result;
48
48
use result:: Result :: { Ok , Err } ;
49
49
use ptr;
50
50
use mem;
51
- use marker:: { Send , Sync , self } ;
51
+ use marker:: { Copy , Send , Sync , self } ;
52
52
use raw:: Repr ;
53
53
// Avoid conflicts with *both* the Slice trait (buggy) and the `slice::raw` module.
54
54
use raw:: Slice as RawSlice ;
@@ -152,6 +152,8 @@ pub trait SliceExt {
152
152
153
153
#[ stable( feature = "clone_from_slice" , since = "1.7.0" ) ]
154
154
fn clone_from_slice ( & mut self , & [ Self :: Item ] ) where Self :: Item : Clone ;
155
+ #[ unstable( feature = "copy_from_slice" , issue = "31755" ) ]
156
+ fn copy_from_slice ( & mut self , src : & [ Self :: Item ] ) where Self :: Item : Copy ;
155
157
}
156
158
157
159
// Use macros to be generic over const/mut
@@ -488,6 +490,16 @@ impl<T> SliceExt for [T] {
488
490
self [ i] . clone_from ( & src[ i] ) ;
489
491
}
490
492
}
493
+
494
+ #[ inline]
495
+ fn copy_from_slice ( & mut self , src : & [ T ] ) where T : Copy {
496
+ assert ! ( self . len( ) == src. len( ) ,
497
+ "destination and source slices have different lengths" ) ;
498
+ unsafe {
499
+ ptr:: copy_nonoverlapping (
500
+ src. as_ptr ( ) , self . as_mut_ptr ( ) , self . len ( ) ) ;
501
+ }
502
+ }
491
503
}
492
504
493
505
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
0 commit comments