File tree Expand file tree Collapse file tree 2 files changed +6
-4
lines changed Expand file tree Collapse file tree 2 files changed +6
-4
lines changed Original file line number Diff line number Diff line change 1
1
---
2
2
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
3
3
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4
- refs/heads/snap-stage3: e014ab9023017ec1c1533a1fbe27288e0b53152f
4
+ refs/heads/snap-stage3: 5fdb0cbb8ce98bdddc947fc1eeabd2efd509aadc
5
5
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
7
7
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
Original file line number Diff line number Diff line change @@ -1941,12 +1941,14 @@ fn head_bad<T>(v: &[T]) -> T {
1941
1941
~~~~
1942
1942
1943
1943
However, we can tell the compiler that the ` head ` function is only for
1944
- copyable types: that is, those that have the ` Copy ` trait.
1944
+ copyable types: that is, those that have the ` Copy ` trait. In that
1945
+ case, we can explicitly create a second copy of the value we are
1946
+ returning using the ` copy ` keyword:
1945
1947
1946
1948
~~~~
1947
1949
// This does
1948
1950
fn head<T: Copy>(v: &[T]) -> T {
1949
- v[0]
1951
+ copy v[0]
1950
1952
}
1951
1953
~~~~
1952
1954
@@ -2137,7 +2139,7 @@ as in this version of `print_all` that copies elements.
2137
2139
fn print_all<T: Printable + Copy>(printable_things: ~[T]) {
2138
2140
let mut i = 0;
2139
2141
while i < printable_things.len() {
2140
- let copy_of_thing = printable_things[i];
2142
+ let copy_of_thing = copy printable_things[i];
2141
2143
copy_of_thing.print();
2142
2144
i += 1;
2143
2145
}
You can’t perform that action at this time.
0 commit comments