mirror of
https://github.com/google/comprehensive-rust.git
synced 2024-12-04 11:39:42 +02:00
Update impl-trait.md (#249)
Adding an extra speaker note why `impl Display` is used very appropriately here and what would go wrong if we tried `T: Display`.
This commit is contained in:
parent
cde1c433f6
commit
6b75f9e69c
@ -28,4 +28,11 @@ The meaning of `impl Trait` is a bit different in the different positions.
|
||||
without naming the type. This can be useful when you don't want to expose the concrete type in a
|
||||
public API.
|
||||
|
||||
This example is great, because it uses `impl Display` twice. It helps to explain that
|
||||
nothing here enforces that it is _the same_ `impl Display` type. If we used a single
|
||||
`T: Display`, it would enforce the constraint that input `T` and return `T` type are the same type.
|
||||
It would not work for this particular function, as the type we expect as input is likely not
|
||||
what `format!` returns. If we wanted to do the same via `: Display` syntax, we'd need two
|
||||
independent generic parameters.
|
||||
|
||||
</details>
|
||||
|
Loading…
Reference in New Issue
Block a user