Skip to content

Better docs for copy_from_slice & clone_from_slice #51701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 11, 2018
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/libcore/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,9 @@ 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
/// // or the destination to be the same size. Here we slice the source, four elements,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the slices must be the same length, so you can slice the source or the destination to be the same size

I spoke with a couple other documentation people and we agreed that this would be better worded as:

Because the slices must be the same length, we'll need to slice the source slice from four elements to two. It will panic if we don't do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

/// // 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]);
Expand Down Expand Up @@ -1607,6 +1610,9 @@ 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
/// // 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..]);
///
/// assert_eq!(src, [1, 2, 3, 4]);
Expand Down