From b75e713792aeba7c2cbace54c679730a05eaa0b9 Mon Sep 17 00:00:00 2001 From: Igor Petruk Date: Mon, 23 Jan 2023 13:38:53 +0000 Subject: [PATCH] Update methods.md (#247) Adding a Q/A about `impl Point`, why is it specified twice. --- src/generics/methods.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/generics/methods.md b/src/generics/methods.md index 9a901b57..66bc4058 100644 --- a/src/generics/methods.md +++ b/src/generics/methods.md @@ -19,3 +19,13 @@ fn main() { println!("p.x = {}", p.x()); } ``` + +
+ +* *Q:* Why `T` is specified twice in `impl Point {}`? Isn't that redundant? + * This is because it is a generic implementation section for generic type. They are independently generic. + * It means these methods are defined for any `T`. + * It is possible to write `impl Point { .. }`. + * `Point` is still generic and you can use `Point`, but methods in this block will only be available for `Point`. + +