feat(lib): update to std::future::Future

BREAKING CHANGE: All usage of async traits (`Future`, `Stream`,
`AsyncRead`, `AsyncWrite`, etc) are updated to newer versions.
This commit is contained in:
Sean McArthur
2019-07-09 15:37:43 -07:00
parent da9b0319ef
commit 8f4b05ae78
37 changed files with 1526 additions and 1548 deletions

View File

@@ -1,6 +1,6 @@
use std::mem;
use futures::{Future, IntoFuture, Poll};
use super::{Future, Pin, Poll, task};
pub(crate) trait Started: Future {
fn started(&self) -> bool;
@@ -9,7 +9,7 @@ pub(crate) trait Started: Future {
pub(crate) fn lazy<F, R>(func: F) -> Lazy<F, R>
where
F: FnOnce() -> R,
R: IntoFuture,
R: Future + Unpin,
{
Lazy {
inner: Inner::Init(func),
@@ -18,8 +18,8 @@ where
// FIXME: allow() required due to `impl Trait` leaking types to this lint
#[allow(missing_debug_implementations)]
pub(crate) struct Lazy<F, R: IntoFuture> {
inner: Inner<F, R::Future>
pub(crate) struct Lazy<F, R> {
inner: Inner<F, R>
}
enum Inner<F, R> {
@@ -31,7 +31,7 @@ enum Inner<F, R> {
impl<F, R> Started for Lazy<F, R>
where
F: FnOnce() -> R,
R: IntoFuture,
R: Future + Unpin,
{
fn started(&self) -> bool {
match self.inner {
@@ -45,21 +45,20 @@ where
impl<F, R> Future for Lazy<F, R>
where
F: FnOnce() -> R,
R: IntoFuture,
R: Future + Unpin,
{
type Item = R::Item;
type Error = R::Error;
type Output = R::Output;
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
match self.inner {
Inner::Fut(ref mut f) => return f.poll(),
Inner::Fut(ref mut f) => return Pin::new(f).poll(cx),
_ => (),
}
match mem::replace(&mut self.inner, Inner::Empty) {
Inner::Init(func) => {
let mut fut = func().into_future();
let ret = fut.poll();
let mut fut = func();
let ret = Pin::new(&mut fut).poll(cx);
self.inner = Inner::Fut(fut);
ret
},
@@ -68,3 +67,6 @@ where
}
}
// The closure `F` is never pinned
impl<F, R: Unpin> Unpin for Lazy<F, R> {}