rust-tw/book-tw

the `use` of generic parameters is not translated accurately

weihanglo opened this issue · 0 comments

For a impl block such as impl<T> MyStruct<T>, the <T> in impl<T> is a declaration of generic parameters. It differs from the latter <T> in MyStruct<T>, which is the use of the former generic parameter declaration. The current translation is not accurate on the fact that generic parameters can be used in the rest of the implementation block after their declarations.

https://rust-lang.tw/book-tw/ch10-03-lifetime-syntax.html#在方法定義中的生命週期詮釋
https://doc.rust-lang.org/book/ch10-03-lifetime-syntax.html#lifetime-annotations-in-method-definitions

  • 生命週期參數宣告在 impl 之後,而且也要在型別名稱之後加上
  • The lifetime parameter declaration after impl and its use after the type name are required

https://rust-lang.tw/book-tw/ch10-01-syntax.html#在方法中定義
https://doc.rust-lang.org/book/ch10-01-syntax.html#in-method-definitions

  • 注意到我們需要在 impl 宣告 T,這樣才代表我們指的是在型別 Point 實作方法
  • Note that we have to declare T just after impl so we can use it to specify that we’re implementing methods on the type Point