From ebf8a92586bd7e5483a4815aa319e6f9a7aee4b6 Mon Sep 17 00:00:00 2001 From: Evgeny Safronov Date: Sun, 11 Jun 2017 13:53:31 +0300 Subject: [PATCH] refactor: prevent double boxing in `boxed` --- src/future/mod.rs | 18 +++++++++++++++++- src/lib.rs | 1 + 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/future/mod.rs b/src/future/mod.rs index 7e278bac88..2122296b35 100644 --- a/src/future/mod.rs +++ b/src/future/mod.rs @@ -308,7 +308,7 @@ pub trait Future { fn boxed(self) -> BoxFuture 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 @@ -1044,3 +1044,19 @@ impl fmt::Debug for ExecuteError { } } } + +trait Boxed: Future { + fn boxed(self) -> BoxFuture; +} + +impl Boxed for F where F: Future + Sized + Send + 'static { + default fn boxed(self) -> BoxFuture { + ::std::boxed::Box::new(self) + } +} + +impl Boxed for BoxFuture { + fn boxed(self) -> BoxFuture { + self + } +} diff --git a/src/lib.rs b/src/lib.rs index ed8c93f96d..7666173c41 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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")]