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
Owned is the garbage collected equivalent of Box, yet at the same time T has to be Sized, while it doesn't have to be for Box. Sames goes for Shared and Arc.
Is this on purpose? Can we relax this trait bound?
I tried sending a Owned<dyn FnMut()> over to my audio thread, but couldn't. :)
Happy to submit a PR for this, if necessary.
The text was updated successfully, but these errors were encountered:
I would like for basedrop to support this, but it's not as simple as relaxing the trait bound. Owned::new needs to take a Sized value since Box::new does as well, and then there needs to be a way to convert e.g. an Owned<T> to an Owned<dyn Trait>. The ability to convert a Box<T> to a Box<dyn Trait> is builtin compiler functionality, and there is an RFC to allow custom smart pointer types to make use of it but it has not be stabilized. It might be possible to hand-roll an acceptable solution that works on stable, where converting to an unsized type requires an explicit method call (and there's the unsize crate which provides a pattern for doing so) but I haven't gotten the chance to really look into it yet.
You can work around this limitation for now by using an Owned<Box<dyn FnMut()>>. It's certainly not ideal, but it will work.
Owned
is the garbage collected equivalent ofBox
, yet at the same timeT
has to beSized
, while it doesn't have to be forBox
. Sames goes forShared
andArc
.Is this on purpose? Can we relax this trait bound?
I tried sending a
Owned<dyn FnMut()>
over to my audio thread, but couldn't. :)Happy to submit a PR for this, if necessary.
The text was updated successfully, but these errors were encountered: