Generic type symbol for impl and Struct

Hello,

I am stuck at understanding the method implementation for generic types:

By declaring T as a generic type after impl, Rust can identify that the type in the angle brackets in Point is a generic type rather than a concrete type. We could have chosen a different name for this generic parameter than the generic parameter declared in the struct definition, but using the same name is conventional.

Does the above mean to imply that we could have something like the following:

impl<T> GenericStruct<U> 

I understand from trying it out that this does not work since the compiler tries to lookup type U. So what is "We could have chosen a different name for this generic parameter than the generic parameter declared in the struct definition, but using the same name is conventional" trying to say? Could someone please explain?

It means you could write:

struct Foo<T>;

impl<U> Foo<U> {}

But using the same name for the declaration and the impl block is conventional.

1 Like

I get it now. Thanks for the quick reply! Appreciate it! <3

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.