Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

https://github.com/rust-lang/rfcs/blob/master/text/1598-gene... has all the gory details, reading that is probably best!


Ok, I did, so here's the answer in case anybody else is confused:

The feature under discussion is "associated type constructors". Rust already has associated types in traits (I didn't know that part and was confused), and what this feature adds is that it allows us to associate a first-order type constructor to a trait.

Since the type constructor is first-order, and first-order type constructors are already present in the base language in the form of generic types, the implementation is simplified to the point that it can reuse the existing infrarstructure for type inference.

---

Apart from that, the reason for this implementation choice seems to be that it's required for precise lifetime management. Almost all datastructures in rust seem to be parameterized with a lifetime argument, even if they have no further type parameters. Since there is no such thing as a second-order lifetime (i.e., a "lifetime constructor" T : (lifetime -> lifetime) -> lifetime), first-order type constructors are enough to handle all issues that pop up because of lifetime management.

---

That actually seems like a very pragmatic design. The only problem I had while reading this RFC is that the combination of "multiple-inheritance" in traits with their built in namespacing leads to some really ugly syntax, e.g., "<T as Foo>::Bar<'a, 'static>;". Is this already idiomatic rust?

There's several more things that confuse me in this RFC, but this is probably the wrong place to discuss these things. Incidentally, what is the right place to talk about this?


> Is this already idiomatic rust?

It's only used for disambiguation cases, extremely rarely. I've been doing Rust almost five years and I think I may have written <T as Foo> once.

> what is the right place to talk about this?

https://internals.rust-lang.org/ is the best place. Probably going to be pretty slow-going until next week, due to the holiday today.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: