#![deny(missing_docs)]
#[macro_use]
extern crate log;
mod lock;
mod slot;
mod util;
#[macro_use]
mod poll;
pub use poll::Poll;
mod task;
pub use task::{Task, TaskData, TaskNotifyData, TaskHandle};
pub mod executor;
mod collect;
mod done;
mod empty;
mod failed;
mod finished;
mod lazy;
mod promise;
mod store;
pub use collect::{collect, Collect};
pub use done::{done, Done};
pub use empty::{empty, Empty};
pub use failed::{failed, Failed};
pub use finished::{finished, Finished};
pub use lazy::{lazy, Lazy};
pub use promise::{promise, Promise, Complete, Canceled};
pub use store::{store, Store, store_notify, StoreNotify};
mod and_then;
mod flatten;
mod fuse;
mod join;
mod map;
mod map_err;
mod or_else;
mod select;
mod then;
pub use and_then::AndThen;
pub use flatten::Flatten;
pub use fuse::Fuse;
pub use join::Join;
pub use map::Map;
pub use map_err::MapErr;
pub use or_else::OrElse;
pub use select::{Select, SelectNext};
pub use then::Then;
pub mod stream;
mod chain;
mod impls;
mod forget;
pub trait Future: Send + 'static {
type Item: Send + 'static;
type Error: Send + 'static;
fn poll(&mut self, task: &mut Task) -> Poll<Self::Item, Self::Error>;
fn schedule(&mut self, task: &mut Task);
fn tailcall(&mut self)
-> Option<Box<Future<Item=Self::Item, Error=Self::Error>>> {
None
}
fn boxed(self) -> Box<Future<Item=Self::Item, Error=Self::Error>>
where Self: Sized
{
Box::new(self)
}
fn map<F, U>(self, f: F) -> Map<Self, F>
where F: FnOnce(Self::Item) -> U + Send + 'static,
U: Send + 'static,
Self: Sized,
{
assert_future::<U, Self::Error, _>(map::new(self, f))
}
fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
where F: FnOnce(Self::Error) -> E + Send + 'static,
E: Send + 'static,
Self: Sized,
{
assert_future::<Self::Item, E, _>(map_err::new(self, f))
}
fn then<F, B>(self, f: F) -> Then<Self, B, F>
where F: FnOnce(Result<Self::Item, Self::Error>) -> B + Send + 'static,
B: IntoFuture,
Self: Sized,
{
assert_future::<B::Item, B::Error, _>(then::new(self, f))
}
fn and_then<F, B>(self, f: F) -> AndThen<Self, B, F>
where F: FnOnce(Self::Item) -> B + Send + 'static,
B: IntoFuture<Error = Self::Error>,
Self: Sized,
{
assert_future::<B::Item, Self::Error, _>(and_then::new(self, f))
}
fn or_else<F, B>(self, f: F) -> OrElse<Self, B, F>
where F: FnOnce(Self::Error) -> B + Send + 'static,
B: IntoFuture<Item = Self::Item>,
Self: Sized,
{
assert_future::<Self::Item, B::Error, _>(or_else::new(self, f))
}
fn select<B>(self, other: B) -> Select<Self, B::Future>
where B: IntoFuture<Item=Self::Item, Error=Self::Error>,
Self: Sized,
{
let f = select::new(self, other.into_future());
assert_future::<(Self::Item, SelectNext<Self, B::Future>),
(Self::Error, SelectNext<Self, B::Future>), _>(f)
}
fn join<B>(self, other: B) -> Join<Self, B::Future>
where B: IntoFuture<Error=Self::Error>,
Self: Sized,
{
let f = join::new(self, other.into_future());
assert_future::<(Self::Item, B::Item), Self::Error, _>(f)
}
fn flatten(self) -> Flatten<Self>
where Self::Item: IntoFuture,
<<Self as Future>::Item as IntoFuture>::Error:
From<<Self as Future>::Error>,
Self: Sized
{
let f = flatten::new(self);
assert_future::<<<Self as Future>::Item as IntoFuture>::Item,
<<Self as Future>::Item as IntoFuture>::Error,
_>(f)
}
fn fuse(self) -> Fuse<Self>
where Self: Sized
{
let f = fuse::new(self);
assert_future::<Self::Item, Self::Error, _>(f)
}
fn forget(self) where Self: Sized {
forget::forget(self);
}
}
fn assert_future<A, B, F>(t: F) -> F
where F: Future<Item=A, Error=B>,
A: Send + 'static,
B: Send + 'static,
{
t
}
pub trait IntoFuture: Send + 'static {
type Future: Future<Item=Self::Item, Error=Self::Error>;
type Item: Send + 'static;
type Error: Send + 'static;
fn into_future(self) -> Self::Future;
}
impl<F: Future> IntoFuture for F {
type Future = F;
type Item = F::Item;
type Error = F::Error;
fn into_future(self) -> F {
self
}
}
impl<T, E> IntoFuture for Result<T, E>
where T: Send + 'static,
E: Send + 'static,
{
type Future = Done<T, E>;
type Item = T;
type Error = E;
fn into_future(self) -> Done<T, E> {
done(self)
}
}