-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for trait objects #72
Comments
No, because we don't know how to trace it. You can write such a thing in a wrapped struct with a custom implementation of |
Correct me if I am wrong, but even if I create a wrapper, it will still contain some sort of pointer to pub struct DynWrapper<T: ?Sized + Trace + Finalize> {
data: T,
}
impl<T: Trace> DynWrapper<T> {
pub fn new(data: T) -> Self {
DynWrapper { data }
}
} But this doesn't work with trait objects, unless I have a |
No, you have to do this on a per-trait-object basis pub struct MyTraitWrapper {
inner: Box<Trait>
} and your If you want to avoid the heap allocation you can do the following: pub struct MyTraitWrapper {
inner: Trait which is also a dynamically sized type and can be directly placed inside |
Thank you for your help. I think I will stick with your first suggestion. |
The original code actually just works in nightly Rust with the |
With the The tracking issue for the required unstable Rust feature is |
Can you wrap a trait object in a
Gc
? I would like to be able to write something like this. As a workaround, I am currently creating aGc<Box<dyn MyTrait>>
, but I don't really like the indirection. I am trying to useGc
the way you would use aBox
orRc
with trait objects.The text was updated successfully, but these errors were encountered: