Notes on GATs

Theres a bit of discussion happening in Rust community on the generic associated types topic. I can not help but add my own thoughts to the pile :-)

I dont intend to write a well-edited post considering all pros and cones (intentional typo to demonstrate how unedited this is). Rather, I just want to dump my experience as is. Ultimately I trust the lang team to make the right call here way more than I trust myself. The post could be read as a bit inflammatory, but my stated goal here is not to sway someones mind by the arguments, but rather expose my own thinking process.

This post is partially prompted by the following comment from the RFC:

I probably have GATs in every project I do write.

It stuck with me, because this is very much the opposite of the experience I have. Ive been using Rust extensively for a while, mostly as an application (as opposed to library) developer, and I cant remember a single instance where I really wanted to have GATs. This is a consequences of my overall code style I try to use abstraction sparingly and rarely reach out for traits. I dont think Ive ever build a meaningful abstraction which was expressed via traits? On the contrary, I try hard to make everything concrete and non-generic on the language level.

Whats more, when I do reach out for traits, most of the time this is to use trait objects, which give me a new runtime capability to use different, substitutable concrete type. For the static,monomorphization based subset of traits I find that most of the time non-trait solution seem to work.

And I think GATs (and associated types in general) dont work with trait objects, which probably explains why, even when I use traits, I dont generally need GATs. Though, it seems to me that lifetime-only subset of GATs actually works with trait objects? That is, lending iterator seems to be object safe?

I guess, the only place where I do, indirectly, want GATs is to make async trait work, but even then, I usually am interested in object-safe async traits, which I think dont need and cant use GATs?


Another disconnection between my usage of Rust and discussion surrounding the GATs is in one of the prominent examples parser combinator library. In practice, for me parser combinators primary use-case was always a vehicle for teaching advanced types (eg, the monads paper uses parsers as one of the examples). For production use-cases Ive encountered, it was always either a hand-written parser, or a full-blown parser generator.