1. erased types (have to use behind pointer, so not shallow dynamic sizing) 2. Existential types
So we can build vtables by hand.
Type safe API to any OOP ABI + tons of stuff OOP people never imagined....let's go!
1. erased types (have to use behind pointer, so not shallow dynamic sizing) 2. Existential types
So we can build vtables by hand.
Type safe API to any OOP ABI + tons of stuff OOP people never imagined....let's go!
How does &dyn MyTrait, which already exist today, not fit the description?
> 2. Existential types
What is that?
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.
Yes, but it is still quite limited: they are not yet supported as associated type in traits or in type aliases.
What prevents one from using a pointer like this already? I'm curious.
> 2. Existential types
Fair, I think.
> So we can build vtables by hand. > > Type safe API to any OOP ABI + tons of stuff OOP people never imagined....let's go!
Is this not already possible?
It is, the anyhow crate does this, for example. It does require unsafe though.