diff options
Diffstat (limited to 'src/libcollections')
| -rw-r--r-- | src/libcollections/lib.rs | 1 | ||||
| -rw-r--r-- | src/libcollections/slice.rs | 24 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index abf50a5fe3e..9c6fdc217dc 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -27,6 +27,7 @@ test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))] #![cfg_attr(test, allow(deprecated))] // rand +#![cfg_attr(not(test), feature(copy_from_slice))] // impl [T] #![cfg_attr(not(stage0), deny(warnings))] #![feature(alloc)] diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index eab69088aa2..1446d00b9ea 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -837,6 +837,30 @@ impl<T> [T] { core_slice::SliceExt::clone_from_slice(self, src) } + /// Copies all elements from `src` into `self`, using a memcpy. + /// + /// The length of `src` must be the same as `self`. + /// + /// # Panics + /// + /// This function will panic if the two slices have different lengths. + /// + /// # Example + /// + /// ```rust + /// #![feature(copy_from_slice)] + /// let mut dst = [0, 0, 0]; + /// let src = [1, 2, 3]; + /// + /// dst.copy_from_slice(&src); + /// assert_eq!(src, dst); + /// ``` + #[unstable(feature = "copy_from_slice", issue = "31755")] + pub fn copy_from_slice(&mut self, src: &[T]) where T: Copy { + core_slice::SliceExt::copy_from_slice(self, src) + } + + /// Copies `self` into a new `Vec`. #[stable(feature = "rust1", since = "1.0.0")] #[inline] |
