Closed Aaron1011 closed 1 year ago
Oh yeah, that's a super good solution! Thank you so much!
I think we can make the Context
type pub(crate)
now, right? And all of the methods on it? It was only public to allow for the way the old make_arena!
macro worked.
@kyren I've changed the visibility of Context
Awesome, thank you! I'm cool with merging this if you are.
Surprisingly, this doesn't require GATs, and is actually simpler than a GAT-based solution. The core idea is to define a trait:
In
Arena
, we use the higher-ranked trait boundR: for<'a> RootProvider<'a>
. Then, writing<R as RootProvider<'gc>>::Root
gives us the root type with some arbitrary lifetime'gc
substituted.The
make_arena
macro can then simply declare the type aliastype MyArenaName = Arena<dyn for<'a> RootProvider<'a, Root = UserRoot<'a>>>
Since a
RootProvider
trait object implementsRootProvider
, the projection<R as RootProvider<'gc>>::Root
will evaluate toUserRoot<'gc>
, without the need to define any additional structs or trait impls.