From 6b75f9e69c6eed59492fde70380682efe142d437 Mon Sep 17 00:00:00 2001 From: Igor Petruk Date: Mon, 23 Jan 2023 13:41:14 +0000 Subject: [PATCH] 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`. --- src/generics/impl-trait.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/generics/impl-trait.md b/src/generics/impl-trait.md index c7ec317a..e4e4105e 100644 --- a/src/generics/impl-trait.md +++ b/src/generics/impl-trait.md @@ -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. +