Skip to content

Commit 709450b

Browse files
authored
Update generic notes to match example (#2720)
Fixes #2716.
1 parent 3726918 commit 709450b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/generics/generic-functions.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ fn main() {
5757
val: u8,
5858
}
5959
60-
pick(123, Foo { val: 7 }, Foo { val: 456 });
60+
pick(false, Foo { val: 7 }, Foo { val: 99 });
6161
```
6262

6363
- This is similar to C++ templates, but Rust partially compiles the generic
6464
function immediately, so that function must be valid for all types matching
65-
the constraints. For example, try modifying `pick` to return `even + odd` if
66-
`n == 0`. Even if only the `pick` instantiation with integers is used, Rust
67-
still considers it invalid. C++ would let you do this.
65+
the constraints. For example, try modifying `pick` to return `left + right` if
66+
`cond` is false. Even if only the `pick` instantiation with integers is used,
67+
Rust still considers it invalid. C++ would let you do this.
6868

6969
- Generic code is turned into non-generic code based on the call sites. This is
7070
a zero-cost abstraction: you get exactly the same result as if you had

0 commit comments

Comments
 (0)