Trait projection

Hey folks,

yesterday I was reading this topic and @quinedot mentioned the term "trait projection". Since then I was looking for a proper definition of it in the context of Rust but I cannot find anything. The best I've found is this about projection in general but it's in the context of C#... Is this definition (at least the first sentence) also applicable to Rust?


I could find “projection” in the rustc dev guide’s glossary.

projection A general term for a "relative path", e.g. x.f is a "field projection", and T::Item is an "associated type projection".

The linked “Goals and clauses” page then goes on to define (associated type/item projection)

A projection consists of an associated item reference along with its inputs P0..Pm:

Projection = <P0 as TraitName<P1..Pn>>::AssocItem<Pn+1..Pm>

The term also appears once in the reference. All in all it seems like it’s not use too much (with associated types) outside of discussions of compiler internals, or details of the language semantics, OTOH, the topic you’ve linked seems to have discussed quite the details of Rust, too, so it seems fitting :slight_smile:

As far as I understand thus, while “associated type” names the whole language construct of associated types in traits conceptually, which can be defined in trait impls and then used in all kinds of places, a “projection” in this context would refer specifically to a kind of type expression for the usage of an associate type, with all the details (which type’s trait implementation, and with what generic parameters for the trait, and with GATs even parameters for the type) filled in. The syntactic element that represents these projections seems to be called QualifiedPathInType as listed here.

The syntax of these is also comparable with the “fully qualified syntax” of trait methods <Type as Trait<Args…>>::method_name.

The usage of the term “projection” you’ve found for C# seems mostly unrelated :wink:


Perfect! That's exactly what I wanted. :slight_smile: Thank you so much!

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.