Skip to content

Commit

Permalink
Rename copy_from -> copy_from_slice
Browse files Browse the repository at this point in the history
  • Loading branch information
ubsan committed Feb 13, 2016
1 parent 5c2c4c4 commit ea0ad1c
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions text/0000-slice-copy.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ Add one method to Primitive Type `slice`.

```rust
impl<T> [T] where T: Copy {
pub fn copy_from(&mut self, src: &[T]);
pub fn copy_from_slice(&mut self, src: &[T]);
}
```

`copy_from` asserts that `src.len() == self.len()`, then `memcpy`s the members into
`self` from `src`. Calling `copy_from` is semantically equivalent to a `memcpy`.
`self` shall have exactly the same members as `src` after a call to `copy_from`.
`copy_from_slice` asserts that `src.len() == self.len()`, then `memcpy`s the
members into `self` from `src`. Calling `copy_from_slice` is semantically
equivalent to a `memcpy`. `self` shall have exactly the same members as `src`
after a call to `copy_from_slice`.

# Drawbacks
[drawbacks]: #drawbacks
Expand All @@ -38,19 +39,20 @@ One new method on `slice`.
# Alternatives
[alternatives]: #alternatives

`copy_from` could be known as `copy_from_slice`, which would follow
`clone_from_slice`.

`copy_from` could be called `copy_to`, and have the order of the arguments
`copy_from_slice` could be called `copy_to`, and have the order of the arguments
switched around. This would follow `ptr::copy_nonoverlapping` ordering, and not
`dst = src` or `.clone_from()` ordering.
`dst = src` or `.clone_from_slice()` ordering.

`copy_from_slice` could panic only if `dst.len() < src.len()`. This would be the
same as what came before, but we would also lose the guarantee that an
uninitialized slice would be fully initialized.

`copy_from` could panic only if `dst.len() < src.len()`. This would be the same
as what came before, but we would also lose the guarantee that an uninitialized
slice would be fully initialized.
`copy_from_slice` could be a free function, as it was in the original draft of
this document. However, there was overwhelming support for it as a method.

`copy_from` could be a free function, as it was in the original draft of this
document. However, there was overwhelming support for it as a method.
`copy_from_slice` could be not merged, and `clone_from_slice` could be
specialized to `memcpy` in cases of `T: Copy`. I think it's good to have a
specific function to do this, however, which asserts that `T: Copy`.

# Unresolved questions
[unresolved]: #unresolved-questions
Expand Down

0 comments on commit ea0ad1c

Please sign in to comment.