3 ms·
> 1. erased types (have to use behind pointer, so not shallow dynamic sizing) How does &dyn MyTrait, which already exist today, not fit the description? > 2.
by littlestymaar 2y ago
> 1. erased types (have to use behind pointer, so not shallow dynamic sizing)
How does &dyn MyTrait, which already exist today, not fit the description?
> 2. Existential types
What is that?
- tialaramex 2y agoWell I have no idea what your parent meant, but existential types (types which we assert to exist but don't specify) is in fact already used in Rust fn goose_iterator() -> impl Iterator<Item=Goose> That type on the right hand side, impl Iterator<Item=Goose> isn't the name of an actual type, that's just a claim about a property of this type, whatever it is. That's an existential type, the type exists, but we're not naming it. In Rust this means goose_iterator() has some specific result type, but we're not allowed to know what that type is exactly (the compiler knows but our program does not), the only thing we're promised is that whatever type it is, does implement this trait with these parameters. You'll see this often with things that return a callable - it's literally not possible to name most of Rust's callables, even though they each have a distinct type you can't utter the name of that type. So we need to use existential types for that case, but you can use them (as I did) to promise only that you're giving back an iterator without nailing down specifically which iterator that is - which would let you swap that iterator in an API without causing an API incompatibility.
- conaclos 2y ago> Well I have no idea what your parent meant, but existential types (types which we assert to exist but don't specify) is in fact already used in Rust Yes, but it is still quite limited: they are not yet supported as associated type in traits or in type aliases.
- Ericson2314 2y agoI need to write the up because no one knows what either of these things are. Every single answer here is wrong.
- ameliaquining 2y agoYeah, this sounds pretty complicated to me but if there's any sketch of a design for how it could work then I'd be interested to read it.