Skip to content
Permalink
Browse files

Drop PinFuture in favor of direct bounds

  • Loading branch information...
aturon committed May 16, 2018
1 parent ec6addf commit 13ff3126bea704271289e8d4f283f45eb0eeebea
Showing with 19 additions and 23 deletions.
  1. +7 −17 futures-core/src/future/mod.rs
  2. +1 −1 futures-core/src/lib.rs
  3. +5 −1 futures-core/src/task/context.rs
  4. +6 −4 futures-core/src/task/mod.rs
@@ -45,7 +45,7 @@ mod either;
/// scheduling a number of callbacks. As with iterators, the combinators are
/// zero-cost: they compile away. You can find the combinators in the
/// [future-util](https://docs.rs/futures-util) crate.
pub trait Future: Unpin {
pub trait Future {
/// The result of the future
type Output;

@@ -113,16 +113,6 @@ pub trait Future: Unpin {
fn poll(&mut self, cx: &mut task::Context) -> Poll<Self::Output>;
}

/// A future that is only pollable in a "pinned" context.
pub trait PinFuture where for<'a> PinMut<'a, Self>: Future {
/// The value produced by the future
type Output;
}

impl<F: Future> PinFuture for F {
type Output = <Self as Future>::Output;
}

impl<'a, F: ?Sized + Future> Future for &'a mut F {
type Output = F::Output;

@@ -131,7 +121,7 @@ impl<'a, F: ?Sized + Future> Future for &'a mut F {
}
}

impl<'a, F: ?Sized + Future> Future for PinMut<'a, F> {
impl<'a, F: ?Sized + Future + Unpin> Future for PinMut<'a, F> {
type Output = F::Output;

fn poll(&mut self, cx: &mut task::Context) -> Poll<Self::Output> {
@@ -140,7 +130,7 @@ impl<'a, F: ?Sized + Future> Future for PinMut<'a, F> {
}

if_std! {
use std::boxed::Box;
use std::boxed::{Box, PinBox};

impl<'a, F: ?Sized + Future> Future for Box<F> {
type Output = F::Output;
@@ -150,15 +140,15 @@ if_std! {
}
}

/*
impl<F: ?Sized + PinFuture> Future for PinBox<F> {
type Output = F::Output;
impl<T, F: ?Sized> Future for PinBox<F>
where for<'a> PinMut<'a, F>: Future<Output = T>
{
type Output = T;

fn poll(&mut self, cx: &mut task::Context) -> Poll<Self::Output> {
self.as_pin_mut().poll(cx)
}
}
*/

impl<F: Future> Future for ::std::panic::AssertUnwindSafe<F> {
type Output = F::Output;
@@ -44,7 +44,7 @@ mod poll;
pub use poll::Poll;

pub mod future;
pub use future::{Future, TryFuture, PinFuture};
pub use future::{Future, TryFuture};

pub mod stream;
pub use stream::Stream;
@@ -1,4 +1,5 @@
use core::fmt;
use core::mem::PinMut;

use executor::Executor;
use task::{TaskObj, Waker};
@@ -81,7 +82,10 @@ if_std! {
///
/// To handle executor errors, use [executor()](self::Context::executor)
/// instead.
pub fn spawn<F>(&mut self, f: F) where F: Future<Output = ()> + 'static + Send {
pub fn spawn<F>(&mut self, f: F)
where F: 'static + Send,
for<'b> PinMut<'b, F>: Future<Output = ()>
{
self.executor()
.spawn_obj(TaskObj::new(f)).unwrap()
}
@@ -100,9 +100,9 @@ impl Drop for TaskObj {
if_std! {
use std::boxed::Box;

// TODO: this should be `PinFuture`
// see https://github.com/rust-lang/rust/issues/50792
unsafe impl<F: Future<Output = ()> + Send + 'static> UnsafePoll for Box<F> {
unsafe impl<F: Send + 'static> UnsafePoll for Box<F>
where for<'a> PinMut<'a, F>: Future<Output = ()>
{
fn into_raw(self) -> *mut () {
unsafe {
mem::transmute(self)
@@ -124,7 +124,9 @@ if_std! {

impl TaskObj {
/// Create a new `TaskObj` by boxing the given future.
pub fn new<F: Future<Output = ()> + Send + 'static>(f: F) -> TaskObj {
pub fn new<F: Send + 'static>(f: F) -> TaskObj
where for<'a> PinMut<'a, F>: Future<Output = ()>
{
TaskObj::from_poll_task(Box::new(f))
}
}

0 comments on commit 13ff312

Please sign in to comment.
You can’t perform that action at this time.