book icon indicating copy to clipboard operation
book copied to clipboard

Trait<Assoc=Type> bounds need docs

Open pnkfelix opened this issue 3 years ago • 0 comments

  • [x] I have checked the latest main branch to see if this has already been fixed
  • [x] I have searched existing issues and pull requests for duplicates

URL to the section(s) of the book with this problem:

https://doc.rust-lang.org/book/ch19-03-advanced-traits.html

Description of the problem:

As far as I can tell, the book does not document trait bounds of the form Type1: Trait<Assoc=Type2>, where the associated type Assoc is constrained to be equal to Type2.

I did a toolbox search of the text as a whole, and did a skim of the text of section 19.03: Advanced Traits, and could not find any discussion or code listing that use that bound form. (There is discussion in that section of default type-expressions for generic parameters, which has a similar syntax at the trait definition site, but a very different meaning.)

Suggested fix:

Add a new part to 19.03 that discussed how to write constraints. Such a section might also delve into more advanced constraints expressible via where-clauses.

Alternatively, one could add the discussion to the chapter that discussed trait bound syntax, 10.02:

https://doc.rust-lang.org/book/ch10-02-traits.html#trait-bound-syntax

pnkfelix avatar Jan 24 '22 18:01 pnkfelix