2 ms·
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 fn goose_i
by tialaramex 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
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.