You've already forked comprehensive-rust
							
							
				mirror of
				https://github.com/google/comprehensive-rust.git
				synced 2025-10-31 08:37:45 +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:
		| @@ -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> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user