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

refactor: prevent double boxing in boxed #513

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/future/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ pub trait Future {
fn boxed(self) -> BoxFuture<Self::Item, Self::Error>
where Self: Sized + Send + 'static
{
::std::boxed::Box::new(self)
Boxed::boxed(self)
}

/// Map this future's result to a different type, returning a new future of
Expand Down Expand Up @@ -1044,3 +1044,19 @@ impl<F> fmt::Debug for ExecuteError<F> {
}
}
}

trait Boxed: Future {
fn boxed(self) -> BoxFuture<Self::Item, Self::Error>;
}

impl<F> Boxed for F where F: Future + Sized + Send + 'static {
default fn boxed(self) -> BoxFuture<Self::Item, Self::Error> {
::std::boxed::Box::new(self)
}
}

impl<I, E> Boxed for BoxFuture<I, E> {
fn boxed(self) -> BoxFuture<Self::Item, Self::Error> {
self
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
#![no_std]
#![deny(missing_docs, missing_debug_implementations)]
#![doc(html_root_url = "https://docs.rs/futures/0.1")]
#![feature(specialization)]

#[macro_use]
#[cfg(feature = "use_std")]
Expand Down