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: simplify ReusableBoxFuture::try_set logic #7057

Closed
wants to merge 1 commit into from

Conversation

yukibtc
Copy link

@yukibtc yukibtc commented Dec 30, 2024

Motivation

Most of the code related to the ReusableBoxFuture::try_set is complex and unsafe.

Solution

Remove the reuse_pin_box function and check directly if the provided future has a different size or alignment from the currently stored with mem::size_of_val and mem::align_of_val.

@yukibtc yukibtc force-pushed the simplify-reusable-box branch from fe96b41 to 314b5e5 Compare December 30, 2024 15:17
// future::Pending<T> is a ZST so this never allocates.
let boxed = mem::replace(&mut this.boxed, Box::pin(future::pending()));
reuse_pin_box(boxed, future, |boxed| this.boxed = Pin::from(boxed))
self.boxed = Box::pin(future);
Copy link
Contributor

Choose a reason for hiding this comment

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

The point of ReusableBoxFuture is to reuse the Box, but this appears to create a new box?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, sorry, my bad. I'm going to close this

@Darksonn Darksonn added A-tokio-util Area: The tokio-util crate M-sync Module: tokio/sync labels Dec 31, 2024
@yukibtc yukibtc closed this Dec 31, 2024
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants