From 26f0299d80ab3fc850c8ba8df91ebc54ba67418f Mon Sep 17 00:00:00 2001 From: JirCep Date: Sat, 1 Oct 2022 22:51:08 +0200 Subject: [PATCH] Trait bounds are discussed later Beside trait bounds are discussed in 10.2 not in 10.1, _monomorphization_ relates to generics in general not only those bound by/to trait. --- src/ch17-02-trait-objects.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ch17-02-trait-objects.md b/src/ch17-02-trait-objects.md index bb43cc6763..328d58d81f 100644 --- a/src/ch17-02-trait-objects.md +++ b/src/ch17-02-trait-objects.md @@ -232,14 +232,14 @@ didn’t mean to pass and so should pass a different type or we should implement Recall in the [“Performance of Code Using Generics”][performance-of-code-using-generics] section in Chapter 10 our discussion on the monomorphization process performed by the -compiler when we use trait bounds on generics: the compiler generates -nongeneric implementations of functions and methods for each concrete type that -we use in place of a generic type parameter. The code that results from -monomorphization is doing *static dispatch*, which is when the compiler knows -what method you’re calling at compile time. This is opposed to *dynamic -dispatch*, which is when the compiler can’t tell at compile time which method -you’re calling. In dynamic dispatch cases, the compiler emits code that at -runtime will figure out which method to call. +compiler on generics: the compiler generates nongeneric implementations +of functions and methods for each concrete type that we use in place of +a generic type parameter. The code that results from monomorphization is +doing *static dispatch*, which is when the compiler knows what method you’re +calling at compile time. This is opposed to *dynamic dispatch*, which is +when the compiler can’t tell at compile time which method you’re calling. +In dynamic dispatch cases, the compiler emits code that at runtime will +figure out which method to call. When we use trait objects, Rust must use dynamic dispatch. The compiler doesn’t know all the types that might be used with the code that’s using trait objects,