-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
util: add ReusableBoxFuture utility #3464
Conversation
Unfortunately the tests can't run with miri because of missing support for polling future trait objects. See rust-lang/miri#1038. |
JM2C: this doesn't belong in sync mod. |
I was not sure which module to put it in. What do you suggest? |
Though it feels useful enough for a crate of its own, maybe just a root item. ( |
{ | ||
let boxed: Box<dyn Future<Output = T> + Send> = Box::new(future); | ||
|
||
let boxed = Box::into_raw(boxed); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let boxed = Box::into_raw(boxed); | |
let boxed = NonNull::from(Box::leak(boxed)); |
Removes the unnecessary unsafe code bellow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks 👍
I have found myself wanting a utility like this a few times, and inspired by #3463, I have now written it.
One question is which module it should go in. I put it in
tokio_util::sync
, but I'm not sure this is the best place.Discussed here.