You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now, the nodes only allow sized types to be stored. The major reason for this is the coercion
that happens inside the destructor to an unsized type so that the collectors can store heterogenous
lists of nodes, which forces our destructor to require T: Sized.
We could hid Inner<_> behind a trait, and solve the problem that way, but I don't like hiding the
strong counts and live status behind a vtable. Devirtualizers & modern cpus are smart it enough this
might not be an issue though. It would just need benchmarking.
We could store two pointers Inner<T> and Inner<dyn Tracable>, but this seems like a lot of overhead.
If rust-lang #65991 was stable, we could
parameterize GetData on T and try upcasting:
traitTraceable{}impl<T: ?Sized>TraceableforT{}traitGetData<T: ?Sized>:Traceable{fnget(&self) -> &T;}impl<T: ?Sized>GetData<T>forT{fnget(&self) -> &T{self}}fnmain(){let x: std::rc::Rc<usize> = std::rc::Rc::new(10);// This works, yay!let y: std::rc::Rc<dynGetData<usize>> = x.clone();// But this will fail because of https://github.com/rust-lang/rust/issues/65991// let z: std::rc::Rc<dyn Traceable> = y.clone();}
There are ways to make this appear to work using nasty transmutes on pointers to pointers, but it's
pretty unclear if they're valid (or will remain valid).
I have yet to find a better way despite many attempts :( I'm hoping I've missed something obvious.
The text was updated successfully, but these errors were encountered:
Right now, the nodes only allow sized types to be stored. The major reason for this is the coercion
that happens inside the destructor to an unsized type so that the collectors can store heterogenous
lists of nodes, which forces our destructor to require
T: Sized
.We could hid
Inner<_>
behind a trait, and solve the problem that way, but I don't like hiding thestrong counts and live status behind a vtable. Devirtualizers & modern cpus are smart it enough this
might not be an issue though. It would just need benchmarking.
We could store two pointers
Inner<T>
andInner<dyn Tracable>
, but this seems like a lot of overhead.If rust-lang #65991 was stable, we could
parameterize
GetData
onT
and try upcasting:There are ways to make this appear to work using nasty transmutes on pointers to pointers, but it's
pretty unclear if they're valid (or will remain valid).
I have yet to find a better way despite many attempts :( I'm hoping I've missed something obvious.
The text was updated successfully, but these errors were encountered: