Skip to content
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

Merged
merged 11 commits into from
Jan 29, 2021
Merged

util: add ReusableBoxFuture utility #3464

merged 11 commits into from
Jan 29, 2021

Conversation

Darksonn
Copy link
Contributor

@Darksonn Darksonn commented Jan 23, 2021

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.

@Darksonn Darksonn added the A-tokio-util Area: The tokio-util crate label Jan 23, 2021
@Darksonn
Copy link
Contributor Author

Unfortunately the tests can't run with miri because of missing support for polling future trait objects. See rust-lang/miri#1038.

@robjtede
Copy link
Contributor

JM2C: this doesn't belong in sync mod.

@Darksonn
Copy link
Contributor Author

I was not sure which module to put it in. What do you suggest?

@robjtede
Copy link
Contributor

robjtede commented Jan 24, 2021

Though it feels useful enough for a crate of its own, maybe just a root item. (tokio_util::ReusableBoxFuture)

{
let boxed: Box<dyn Future<Output = T> + Send> = Box::new(future);

let boxed = Box::into_raw(boxed);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let boxed = Box::into_raw(boxed);
let boxed = NonNull::from(Box::leak(boxed));

Removes the unnecessary unsafe code bellow

Copy link
Member

@carllerche carllerche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio-util Area: The tokio-util crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants