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 lifetime parameter to ReusableBoxFuture #3762

Merged
merged 4 commits into from Feb 9, 2022

Conversation

Kestrer
Copy link
Contributor

@Kestrer Kestrer commented May 7, 2021

Motivation

ReusableBoxFuture currently only supports 'static futures. However I don't think this limitation is necessary.

Solution

Add a lifetime parameter to ReusableBoxFuture that represents the lifetime of the contained future. ReusableBoxFuture<T> becomes ReusableBoxFuture<'static, T>.

This is a breaking change. If that's undesirable, this could potentially be added as a separate type (but I can't think of a good name for it).

@Darksonn Darksonn added A-tokio-util Area: The tokio-util crate M-sync Module: tokio/sync labels May 8, 2021
Copy link
Contributor

@udoprog udoprog left a comment

Choose a reason for hiding this comment

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

Implementation looks correct to me, but can't speak to whether we want to add a breaking change to tokio-util or not at this point.


// SAFETY: Box::into_raw does not return null pointers.
let boxed = unsafe { NonNull::new_unchecked(boxed) };
let boxed = NonNull::from(Box::leak(boxed));
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a nice change which should be incorporated even if the overall PR isn't accepted!

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really like going through references though. The unsafety rules get a lot more complicated when you do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Darksonn Box::into_raw actually uses Box::leak internally, and NonNull::from(Box::leak(boxed)) was the reason that Box::into_non_null was decided to not be added, so I am pretty sure that this would be fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough.

@tobz tobz added the S-breaking-change A breaking change that requires manual coordination to be released. label Dec 6, 2021
@github-actions github-actions bot added the R-loom Run loom tests on this PR label Feb 9, 2022
@tobz tobz merged commit 9c688ec into tokio-rs:master Feb 9, 2022
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 M-sync Module: tokio/sync R-loom Run loom tests on this PR S-breaking-change A breaking change that requires manual coordination to be released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants