mirror of
https://github.com/google/comprehensive-rust.git
synced 2024-12-11 13:18:43 +02:00
Update methods.md (#247)
Adding a Q/A about `impl<T> Point<T>`, why is it specified twice.
This commit is contained in:
parent
05cc2ff480
commit
b75e713792
@ -19,3 +19,13 @@ fn main() {
|
||||
println!("p.x = {}", p.x());
|
||||
}
|
||||
```
|
||||
|
||||
<details>
|
||||
|
||||
* *Q:* Why `T` is specified twice in `impl<T> Point<T> {}`? 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<u32> { .. }`.
|
||||
* `Point` is still generic and you can use `Point<f64>`, but methods in this block will only be available for `Point<u32>`.
|
||||
|
||||
</details>
|
||||
|
Loading…
Reference in New Issue
Block a user