diff options
| author | Nicholas Mazzuca <npmazzuca@gmail.com> | 2016-02-22 23:06:53 -0800 |
|---|---|---|
| committer | Nicholas Mazzuca <npmazzuca@gmail.com> | 2016-02-25 21:20:41 -0800 |
| commit | e12b1f9424512e39c3d64f955a3bb913707b41d8 (patch) | |
| tree | 1a24cea210b3902aa775acf98b7b4cfb9612762b /src/libcore | |
| parent | 8842e28be8857e8e37591e2dec469d6720c278cb (diff) | |
| download | rust-e12b1f9424512e39c3d64f955a3bb913707b41d8.tar.gz rust-e12b1f9424512e39c3d64f955a3bb913707b41d8.zip | |
Add unstable copy_from_slice
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/slice.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 40041c748e7..afda70f4fcc 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -48,7 +48,7 @@ use result::Result; use result::Result::{Ok, Err}; use ptr; use mem; -use marker::{Send, Sync, self}; +use marker::{Copy, Send, Sync, self}; use raw::Repr; // Avoid conflicts with *both* the Slice trait (buggy) and the `slice::raw` module. use raw::Slice as RawSlice; @@ -152,6 +152,8 @@ pub trait SliceExt { #[stable(feature = "clone_from_slice", since = "1.7.0")] fn clone_from_slice(&mut self, &[Self::Item]) where Self::Item: Clone; + #[unstable(feature = "copy_from_slice", issue = "31755")] + fn copy_from_slice(&mut self, src: &[Self::Item]) where Self::Item: Copy; } // Use macros to be generic over const/mut @@ -488,6 +490,16 @@ impl<T> SliceExt for [T] { self[i].clone_from(&src[i]); } } + + #[inline] + fn copy_from_slice(&mut self, src: &[T]) where T: Copy { + assert!(self.len() == src.len(), + "destination and source slices have different lengths"); + unsafe { + ptr::copy_nonoverlapping( + src.as_ptr(), self.as_mut_ptr(), self.len()); + } + } } #[stable(feature = "rust1", since = "1.0.0")] |
