Skip to content

Commit ea0ad1c

Browse files
committed
Rename copy_from -> copy_from_slice
1 parent 5c2c4c4 commit ea0ad1c

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

text/0000-slice-copy.md

+16-14
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ Add one method to Primitive Type `slice`.
2222

2323
```rust
2424
impl<T> [T] where T: Copy {
25-
pub fn copy_from(&mut self, src: &[T]);
25+
pub fn copy_from_slice(&mut self, src: &[T]);
2626
}
2727
```
2828

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

3334
# Drawbacks
3435
[drawbacks]: #drawbacks
@@ -38,19 +39,20 @@ One new method on `slice`.
3839
# Alternatives
3940
[alternatives]: #alternatives
4041

41-
`copy_from` could be known as `copy_from_slice`, which would follow
42-
`clone_from_slice`.
43-
44-
`copy_from` could be called `copy_to`, and have the order of the arguments
42+
`copy_from_slice` could be called `copy_to`, and have the order of the arguments
4543
switched around. This would follow `ptr::copy_nonoverlapping` ordering, and not
46-
`dst = src` or `.clone_from()` ordering.
44+
`dst = src` or `.clone_from_slice()` ordering.
45+
46+
`copy_from_slice` could panic only if `dst.len() < src.len()`. This would be the
47+
same as what came before, but we would also lose the guarantee that an
48+
uninitialized slice would be fully initialized.
4749

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

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

5557
# Unresolved questions
5658
[unresolved]: #unresolved-questions

0 commit comments

Comments
 (0)