Skip to content

Commit d491e87

Browse files
authored
Merge pull request #3367 from bravequickcleverfibreyarn/ch17-02-trait-objects.md
ch17-02: Monomorphization applies to generics in general
2 parents f8efec5 + a3d5796 commit d491e87

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/ch18-02-trait-objects.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,16 +222,15 @@ didn’t mean to pass and so should pass a different type or we should implement
222222
### Trait Objects Perform Dynamic Dispatch
223223

224224
Recall in the [“Performance of Code Using
225-
Generics”][performance-of-code-using-generics]<!-- ignore --> section in
226-
Chapter 10 our discussion on the monomorphization process performed by the
227-
compiler when we use trait bounds on generics: the compiler generates
228-
nongeneric implementations of functions and methods for each concrete type that
229-
we use in place of a generic type parameter. The code that results from
230-
monomorphization is doing _static dispatch_, which is when the compiler knows
231-
what method you’re calling at compile time. This is opposed to _dynamic
232-
dispatch_, which is when the compiler can’t tell at compile time which method
233-
you’re calling. In dynamic dispatch cases, the compiler emits code that at
234-
runtime will figure out which method to call.
225+
Generics”][performance-of-code-using-generics]<!-- ignore --> section in Chapter
226+
10 our discussion on the monomorphization process performed on generics by the
227+
compiler: the compiler generates nongeneric implementations of functions and
228+
methods for each concrete type that we use in place of a generic type parameter.
229+
The code that results from monomorphization is doing _static dispatch_, which is
230+
when the compiler knows what method you’re calling at compile time. This is
231+
opposed to _dynamic dispatch_, which is when the compiler can’t tell at compile
232+
time which method you’re calling. In dynamic dispatch cases, the compiler emits
233+
code that at runtime will figure out which method to call.
235234

236235
When we use trait objects, Rust must use dynamic dispatch. The compiler doesn’t
237236
know all the types that might be used with the code that’s using trait objects,

0 commit comments

Comments
 (0)