5 ms·
Looking forward to when Rust gets 1. erased types (have to use behind pointer, so not shallow dynamic sizing) 2. Existential types So we can build vtables by
by Ericson2314 2y ago
Looking forward to when Rust gets
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!
- LoganDark 2y ago> 1. erased types (have to use behind pointer, so not shallow dynamic sizing) 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?
- steveklabnik 2y ago> Is this not already possible? It is, the anyhow crate does this, for example. It does require unsafe though.
- Ericson2314 2y agoI mean safely build vtables. Of course, we can already do everything unsafely.
- 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.
- pjmlp 2y agoYou can already get there with std::any, also I imagine you will have some fun digging into COM and WinRT support work done by Microsoft.
- Ericson2314 2y agoI want to safely build vtables by hand. Of course we can already do everything unsafely with nasty casts.
- BlackFly 2y agoExistential types already exist as `impl Trait` for method parameters, unfortunately return position impl traits aren't fully existential because you can only return one type from a function.
- Ericson2314 2y agoExistential quantification is type of variable bindings. You can't point to a think that doesn't bind a variable and say it's the same thing.
- BlackFly 2y agoI have absolutely no idea what you're trying to say. The RPIT will be bound by the caller and there exists a type such that the declared trait is implemented. Meanwhile an impl parameter will be bound within the method with some type existing such that the trait is implemented. That is the implication of existential, "there exists a type such that...".