-
-
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 lifetime parameter to ReusableBoxFuture #3762
Conversation
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.
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)); |
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.
This is a nice change which should be incorporated even if the overall PR isn't accepted!
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.
I don't really like going through references though. The unsafety rules get a lot more complicated when you do.
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.
@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.
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.
Fair enough.
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>
becomesReusableBoxFuture<'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).