@@ -22,13 +22,14 @@ Add one method to Primitive Type `slice`.
22
22
23
23
``` rust
24
24
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 ]);
26
26
}
27
27
```
28
28
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 ` .
32
33
33
34
# Drawbacks
34
35
[ drawbacks ] : #drawbacks
@@ -38,19 +39,20 @@ One new method on `slice`.
38
39
# Alternatives
39
40
[ alternatives ] : #alternatives
40
41
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
45
43
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.
47
49
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.
51
52
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 ` .
54
56
55
57
# Unresolved questions
56
58
[ unresolved ] : #unresolved-questions
0 commit comments