From 4eca24700be4cf9f1fad3e7674e4849f4de234a1 Mon Sep 17 00:00:00 2001 From: Anirudh Balaji Date: Fri, 22 Jun 2018 00:20:51 -0700 Subject: [PATCH 1/5] 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). --- src/libcore/slice/mod.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 6f4c130d8f318..01db55a00f647 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -1541,6 +1541,10 @@ impl [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] { /// 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]); From 57f7f22fe46a08c197e4cd1d2e78df9de4c00798 Mon Sep 17 00:00:00 2001 From: Anirudh Balaji Date: Sun, 24 Jun 2018 15:31:03 -0700 Subject: [PATCH 2/5] Make line-breaking more consistent. --- src/libcore/slice/mod.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 01db55a00f647..a6d95b1182541 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -1541,10 +1541,9 @@ impl [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. + /// // 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]); @@ -1611,10 +1610,9 @@ impl [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. + /// // 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]); From c95fba7b5b7cc3a923707df414f4bc8258400d52 Mon Sep 17 00:00:00 2001 From: Anirudh Balaji Date: Wed, 27 Jun 2018 13:49:50 -0700 Subject: [PATCH 3/5] Nit: Remove leading whitespace --- src/libcore/slice/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index a6d95b1182541..0ee4c0bdbe7f9 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -1541,7 +1541,7 @@ impl [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 + /// // 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..]); @@ -1610,7 +1610,7 @@ impl [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 + /// // 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..]); From c90a821d43dee1ff0d04d84a9adb4ec11dbe6c47 Mon Sep 17 00:00:00 2001 From: Anirudh Balaji Date: Mon, 9 Jul 2018 13:41:46 -0700 Subject: [PATCH 4/5] Add "or destination" to {copy, clone}_from_slice example --- src/libcore/slice/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 0ee4c0bdbe7f9..c41776a14605e 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -1541,8 +1541,8 @@ impl [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, + /// // Note: the slices must be the same length, so you can slice the source + /// // or the destination 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..]); /// @@ -1610,8 +1610,8 @@ impl [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, + /// // Note: the slices must be the same length, so you can slice the source + /// // or the destination 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..]); /// From 4b51484fed75750a84d8422d26a9a7e6c06294e0 Mon Sep 17 00:00:00 2001 From: Anirudh Balaji Date: Tue, 10 Jul 2018 10:56:58 -0700 Subject: [PATCH 5/5] Change wording for {copy, clone}_from_slice --- src/libcore/slice/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index c41776a14605e..a0270d747a9d5 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -1541,9 +1541,9 @@ impl [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 - /// // or the destination 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. + /// // Because the slices have to be the same length, + /// // we slice the source slice from four elements + /// // to two. It will panic if we don't do this. /// dst.clone_from_slice(&src[2..]); /// /// assert_eq!(src, [1, 2, 3, 4]); @@ -1610,9 +1610,9 @@ impl [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 - /// // or the destination 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. + /// // Because the slices have to be the same length, + /// // we slice the source slice from four elements + /// // to two. It will panic if we don't do this. /// dst.copy_from_slice(&src[2..]); /// /// assert_eq!(src, [1, 2, 3, 4]);