1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Future utilities.

use futures::Future;

/// Boxed future.
pub type BoxFuture<Item, Error> = Box<Future<Item = Item, Error = Error>>;

/// Future utility extensions.
pub trait FutureExt: Future + Sized {
    /// Boxes a future.
    fn into_box(self) -> Box<Future<Item = Self::Item, Error = Self::Error>>;
}

impl<T: Future + 'static> FutureExt for T {
    fn into_box(self) -> Box<Future<Item = Self::Item, Error = Self::Error>> {
        Box::new(self)
    }
}

pub mod boxfuture {
    use futures::future;
    use futures::future::FutureResult;

    /// Creates a boxed future result.
    pub fn ok<T, E>(t: T) -> Box<FutureResult<T, E>> {
        Box::new(future::ok(t))
    }
}