diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2013-06-15 21:36:55 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2013-06-16 12:47:36 -0400 |
| commit | 5fdb0cbb8ce98bdddc947fc1eeabd2efd509aadc (patch) | |
| tree | cd3c812db13cbb4409209051c73d41cca81ea151 /doc/tutorial.md | |
| parent | e014ab9023017ec1c1533a1fbe27288e0b53152f (diff) | |
| download | rust-5fdb0cbb8ce98bdddc947fc1eeabd2efd509aadc.tar.gz rust-5fdb0cbb8ce98bdddc947fc1eeabd2efd509aadc.zip | |
Correct tutorial tests
Diffstat (limited to 'doc/tutorial.md')
| -rw-r--r-- | doc/tutorial.md | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/doc/tutorial.md b/doc/tutorial.md index c0b939ddac5..f69f569faee 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -1941,12 +1941,14 @@ fn head_bad<T>(v: &[T]) -> T { ~~~~ However, we can tell the compiler that the `head` function is only for -copyable types: that is, those that have the `Copy` trait. +copyable types: that is, those that have the `Copy` trait. In that +case, we can explicitly create a second copy of the value we are +returning using the `copy` keyword: ~~~~ // This does fn head<T: Copy>(v: &[T]) -> T { - v[0] + copy v[0] } ~~~~ @@ -2137,7 +2139,7 @@ as in this version of `print_all` that copies elements. fn print_all<T: Printable + Copy>(printable_things: ~[T]) { let mut i = 0; while i < printable_things.len() { - let copy_of_thing = printable_things[i]; + let copy_of_thing = copy printable_things[i]; copy_of_thing.print(); i += 1; } |
