about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAnirudh Balaji <anirudhb@users.noreply.github.com>2018-06-22 00:20:51 -0700
committerGitHub <noreply@github.com>2018-06-22 00:20:51 -0700
commit4eca24700be4cf9f1fad3e7674e4849f4de234a1 (patch)
treefd87e6f031012188d42704761a484453fdd2a744
parent4b17d31f1147f840231c43b1ac1478a497af20df (diff)
downloadrust-4eca24700be4cf9f1fad3e7674e4849f4de234a1.tar.gz
rust-4eca24700be4cf9f1fad3e7674e4849f4de234a1.zip
Add explanation for (copy, clone)_from_slice
It elaborates over why we have to slice the 4-size src to 2-size (same as dst).
-rw-r--r--src/libcore/slice/mod.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs
index 6f4c130d8f3..01db55a00f6 100644
--- a/src/libcore/slice/mod.rs
+++ b/src/libcore/slice/mod.rs
@@ -1541,6 +1541,10 @@ impl<T> [T] {
     /// let src = [1, 2, 3, 4];
     /// let mut dst = [0, 0];
     ///
+    /// // Note: the slices must be the same length, so
+    /// // you can slice the source to be the same size.
+    /// // Here we slice the source, four elements, to two, the same size
+    /// // as the destination slice. It *will* panic if we don't do this.
     /// dst.clone_from_slice(&src[2..]);
     ///
     /// assert_eq!(src, [1, 2, 3, 4]);
@@ -1607,6 +1611,10 @@ impl<T> [T] {
     /// let src = [1, 2, 3, 4];
     /// let mut dst = [0, 0];
     ///
+    /// // Note: the slices must be the same length, so
+    /// // you can slice the source to be the same size.
+    /// // Here we slice the source, four elements, to two, the same size
+    /// // as the destination slice. It *will* panic if we don't do this.
     /// dst.copy_from_slice(&src[2..]);
     ///
     /// assert_eq!(src, [1, 2, 3, 4]);