@@ -48,7 +48,7 @@ use result::Result;
4848use result:: Result :: { Ok , Err } ;
4949use ptr;
5050use mem;
51- use marker:: { Send , Sync , self } ;
51+ use marker:: { Copy , Send , Sync , self } ;
5252use raw:: Repr ;
5353// Avoid conflicts with *both* the Slice trait (buggy) and the `slice::raw` module.
5454use raw:: Slice as RawSlice ;
@@ -152,6 +152,8 @@ pub trait SliceExt {
152152
153153 #[ stable( feature = "clone_from_slice" , since = "1.7.0" ) ]
154154 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 ;
155157}
156158
157159// Use macros to be generic over const/mut
@@ -488,6 +490,16 @@ impl<T> SliceExt for [T] {
488490 self [ i] . clone_from ( & src[ i] ) ;
489491 }
490492 }
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+ }
491503}
492504
493505#[ stable( feature = "rust1" , since = "1.0.0" ) ]
0 commit comments