simplist 0.0.5

plain and simple http, for when you just want to make a darn request! supports tokio-based async, traditional sync and async-await models.
Documentation
use futures::Poll;
use futures::future;
use futures::future::Future;
use futures::future::FutureResult;



pub fn completed<T, E>(value: T) -> FutureResult<T, E> {
    future::result(Ok(value))
}

pub fn failed<T, E>(value: E) -> FutureResult<T, E> {
    future::result(Err(value))
}

pub fn from<T, E>(value: Result<T, E>) -> FutureResult<T, E> {
    future::result(value)
}



// a future that can contain one of two types. this lets us return an `impl Future` for two distinct future types,
// without needing to resort to dynamic dispatch.
//
// todo: allow an arbitrary number of future types and select between all of them.
pub enum OneOfFuture<T1, T2, TItem, TError>
    where T1: Future<Item = TItem, Error = TError>,
          T2: Future<Item = TItem, Error = TError>, {

    A(T1),
    B(T2),
}

impl<T1, T2, TItem, TError> Future for OneOfFuture<T1, T2, TItem, TError>
    where T1: Future<Item = TItem, Error = TError>,
          T2: Future<Item = TItem, Error = TError>, {

    type Item  = T1::Item;
    type Error = T1::Error;

    fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
        match *self {
            OneOfFuture::A(ref mut x) => x.poll(),
            OneOfFuture::B(ref mut x) => x.poll(),
        }
    }

    fn wait(self) -> Result<Self::Item, Self::Error>
        where Self: Sized {

        match self {
            OneOfFuture::A(x) => x.wait(),
            OneOfFuture::B(x) => x.wait(),
        }
    }
}


// todo: "unsync" version of this module.
pub mod sync {
    use futures::Async;
    use futures::Future;
    use futures::Poll;
    use futures::sync::oneshot::channel;
    use futures::sync::oneshot::Receiver;
    use futures::sync::oneshot::Sender;


    pub fn source<T, E>() -> (TaskSource<T, E>, Task<T, E>) {
        let (send, receive) = channel();

        let source = TaskSource { a: send };
        let task   = Task { a: receive };

        (source, task)
    }


    #[derive(Debug)]
    pub struct TaskSource<T, E> {
        a: Sender<Result<T, E>>,
    }

    impl<T, E> TaskSource<T, E> {
        #[inline]
        pub fn done(self, result: Result<T, E>) -> Result<(), Result<T, E>> {
            self.a.send(result)
        }

        #[inline]
        pub fn completed(self, value: T) -> Result<(), T> {
            let value = Ok(value);

            self.done(value).map_err(|x| {
                match x {
                    Ok(value) => value,
                    _         => panic!(d!["invariant broken: result must be ok()"]),
                }
            })
        }

        #[inline]
        pub fn failed(self, error: E) -> Result<(), E> {
            let value = Err(error);

            self.done(value).map_err(|x| {
                match x {
                    Err(value) => value,
                    _          => panic!(d!["invariant broken: result must be err()"]),
                }
            })
        }
    }


    #[derive(Debug)]
    pub struct Task<T, E> {
        a: Receiver<Result<T, E>>,
    }

    impl<T, E> Future for Task<T, E> {
        type Item  = T;
        type Error = E;

        fn poll(&mut self) -> Poll<T, E> {
            match self.a.poll() {
                Err(_)              => panic!(d!["task was cancelled"]),
                Ok(Async::NotReady) => Ok(Async::NotReady),
                Ok(Async::Ready(x)) => {
                    match x {
                        Ok(y)  => Ok(Async::Ready(y)),
                        Err(y) => Err(y),
                    }
                },
            }
        }
    }
}