From 709450bfadfc1007a80a6818eac8cde58ed29434 Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Wed, 23 Apr 2025 05:05:18 -0400 Subject: [PATCH] Update generic notes to match example (#2720) Fixes #2716. --- src/generics/generic-functions.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/generics/generic-functions.md b/src/generics/generic-functions.md index a18e90b1..2bad39a3 100644 --- a/src/generics/generic-functions.md +++ b/src/generics/generic-functions.md @@ -57,14 +57,14 @@ fn main() { val: u8, } - pick(123, Foo { val: 7 }, Foo { val: 456 }); + pick(false, Foo { val: 7 }, Foo { val: 99 }); ``` - This is similar to C++ templates, but Rust partially compiles the generic function immediately, so that function must be valid for all types matching - the constraints. For example, try modifying `pick` to return `even + odd` if - `n == 0`. Even if only the `pick` instantiation with integers is used, Rust - still considers it invalid. C++ would let you do this. + the constraints. For example, try modifying `pick` to return `left + right` if + `cond` is false. Even if only the `pick` instantiation with integers is used, + Rust still considers it invalid. C++ would let you do this. - Generic code is turned into non-generic code based on the call sites. This is a zero-cost abstraction: you get exactly the same result as if you had