Skip to content

Commit efa5dc1

Browse files
igor-petrukNoahDragon
authored andcommitted
Update methods.md (google#247)
Adding a Q/A about `impl<T> Point<T>`, why is it specified twice.
1 parent bcee64f commit efa5dc1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/generics/methods.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,13 @@ fn main() {
1919
println!("p.x = {}", p.x());
2020
}
2121
```
22+
23+
<details>
24+
25+
* *Q:* Why `T` is specified twice in `impl<T> Point<T> {}`? Isn't that redundant?
26+
* This is because it is a generic implementation section for generic type. They are independently generic.
27+
* It means these methods are defined for any `T`.
28+
* It is possible to write `impl Point<u32> { .. }`.
29+
* `Point` is still generic and you can use `Point<f64>`, but methods in this block will only be available for `Point<u32>`.
30+
31+
</details>

0 commit comments

Comments
 (0)