struct StructName<T, U> {
field1: T,
field2: U,
}
impl<T, U> StructName<T, U> {
}
As in the code above, the generic argument list in the impl block and the struct generic argument list must match, otherwise the Rust compiler will give an error.
I have three questions:
- Why do they need to be consistent?
- What is the relationship between them?
- Given that they are consistent, why do they need to be explicitly repeated instead of the compiler implicitly filling the impl block with the generic argument list in the struct?
New contributor
sundegan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.