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 1 commit
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
8 changes: 8 additions & 0 deletions src/libcore/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: The line breaks look somewhat strange here, the first two lines break at a different width than the last two lines.

/// // 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]);
Expand Down