diff options
| author | bors <bors@rust-lang.org> | 2016-02-26 09:16:03 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-02-26 09:16:03 +0000 |
| commit | 09130044ce7429beb95742afa7fd371960dbe607 (patch) | |
| tree | 9a0ebbc985192ef380aecb1af54214781fc6cdfa /src/libcollections | |
| parent | 9c6a0088fbdae5a6554c39f8db9207c1b878eb05 (diff) | |
| parent | e12b1f9424512e39c3d64f955a3bb913707b41d8 (diff) | |
Auto merge of #31834 - ubsan:copy_from_slice, r=alexcrichton
implements rust-lang/rfcs#1419 r? alexcrichton
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] |
