diff --git a/src/ch10-01-syntax.md b/src/ch10-01-syntax.md index 0eb8b56892..ed3f247564 100644 --- a/src/ch10-01-syntax.md +++ b/src/ch10-01-syntax.md @@ -210,13 +210,20 @@ Here, we’ve defined a method named `x` on `Point` that returns a reference to the data in the field `x`. Note that we have to declare `T` just after `impl` so we can use it to specify -that we’re implementing methods on the type `Point`. By declaring `T` as a +that we’re implementing methods on the type `Point`. By declaring `T` as a generic type after `impl`, Rust can identify that the type in the angle -brackets in `Point` is a generic type rather than a concrete type. - -We could, for example, implement methods only on `Point` instances rather -than on `Point` instances with any generic type. In Listing 10-10 we use the -concrete type `f32`, meaning we don’t declare any types after `impl`. +brackets in `Point` is a generic type rather than a concrete type. Because this +is declaring the generic again, we could have chosen a different name for the +generic parameter than the generic parameter declared in the struct definition, +but using the same name is conventional. Methods written within an `impl` that +declares the generic type will be defined on any instance of the type, no +matter what concrete type ends up substituting for the generic type. + +The other option we have is defining methods on the type with some constraint +on the generic type. We could, for example, implement methods only on +`Point` instances rather than on `Point` instances with any generic +type. In Listing 10-10 we use the concrete type `f32`, meaning we don’t declare +any types after `impl`. Filename: src/main.rs