pub(crate) struct ReusableBoxFuture<T> {
boxed: NonNull<dyn Future<Output = T> + Send>,
}Expand description
A reusable Pin<Box<dyn Future<Output = T> + Send>>.
This type lets you replace the future stored in the box without reallocating when the size and alignment permits this.
Fields§
§boxed: NonNull<dyn Future<Output = T> + Send>Implementations§
Source§impl<T> ReusableBoxFuture<T>
impl<T> ReusableBoxFuture<T>
Sourcepub(crate) fn new<F>(future: F) -> Self
pub(crate) fn new<F>(future: F) -> Self
Create a new ReusableBoxFuture<T> containing the provided future.
Sourcepub(crate) fn set<F>(&mut self, future: F)
pub(crate) fn set<F>(&mut self, future: F)
Replaces the future currently stored in this box.
This reallocates if and only if the layout of the provided future is different from the layout of the currently stored future.
Sourcepub(crate) fn try_set<F>(&mut self, future: F) -> Result<(), F>
pub(crate) fn try_set<F>(&mut self, future: F) -> Result<(), F>
Replaces the future currently stored in this box.
This function never reallocates, but returns an error if the provided future has a different size or alignment from the currently stored future.
Sourceunsafe fn set_same_layout<F>(&mut self, future: F)
unsafe fn set_same_layout<F>(&mut self, future: F)
Sets the current future.
§Safety
This function requires that the layout of the provided future is the
same as self.layout.
Trait Implementations§
Source§impl<T> Debug for ReusableBoxFuture<T>
impl<T> Debug for ReusableBoxFuture<T>
Source§impl<T> Drop for ReusableBoxFuture<T>
impl<T> Drop for ReusableBoxFuture<T>
Source§impl<T> Future for ReusableBoxFuture<T>
impl<T> Future for ReusableBoxFuture<T>
impl<T> Send for ReusableBoxFuture<T>
impl<T> Sync for ReusableBoxFuture<T>
impl<T> Unpin for ReusableBoxFuture<T>
Auto Trait Implementations§
impl<T> Freeze for ReusableBoxFuture<T>
impl<T> !RefUnwindSafe for ReusableBoxFuture<T>
impl<T> UnsafeUnpin for ReusableBoxFuture<T>
impl<T> !UnwindSafe for ReusableBoxFuture<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<F> IntoFuture for Fwhere
F: Future,
impl<F> IntoFuture for Fwhere
F: Future,
Source§type IntoFuture = F
type IntoFuture = F
Which kind of future are we turning this into?
Source§fn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
Creates a future from a value. Read more