chore: remove tokio-futures facade crate (#1327)

This switches from using the tokio-futures facade to referencing
futures-* crates directly.
This commit is contained in:
Carl Lerche
2019-07-19 13:11:46 -07:00
committed by GitHub
parent b89ed00a0d
commit a99fa6e096
39 changed files with 69 additions and 187 deletions
+7 -6
View File
@@ -1,18 +1,19 @@
#![allow(deprecated)]
use std::fmt;
use std::io::{self, Read, Write};
use std::pin::Pin;
use std::task::{Context, Poll};
use crate::decoder::Decoder;
use crate::encoder::Encoder;
use crate::framed_read::{framed_read2, framed_read2_with_buffer, FramedRead2};
use crate::framed_write::{framed_write2, framed_write2_with_buffer, FramedWrite2};
use tokio_futures::{Sink, Stream};
use tokio_io::{AsyncRead, AsyncWrite};
use bytes::BytesMut;
use futures_core::Stream;
use futures_sink::Sink;
use std::fmt;
use std::io::{self, Read, Write};
use std::pin::Pin;
use std::task::{Context, Poll};
/// A unified `Stream` and `Sink` interface to an underlying I/O object, using
/// the `Encoder` and `Decoder` traits to encode and decode frames.
+6 -5
View File
@@ -1,14 +1,15 @@
use std::fmt;
use std::pin::Pin;
use std::task::{Context, Poll};
use super::framed::Fuse;
use super::Decoder;
use tokio_futures::{Sink, Stream};
use tokio_io::AsyncRead;
use bytes::BytesMut;
use futures_core::Stream;
use futures_sink::Sink;
use log::trace;
use std::fmt;
use std::pin::Pin;
use std::task::{Context, Poll};
/// A `Stream` of messages decoded from an `AsyncRead`.
pub struct FramedRead<T, D> {
+11 -9
View File
@@ -1,16 +1,17 @@
#![allow(deprecated)]
use log::trace;
use std::fmt;
use std::io::{self, Read};
use super::framed::Fuse;
use crate::decoder::Decoder;
use crate::encoder::Encoder;
use tokio_futures::{Sink, Stream};
use tokio_io::{AsyncRead, AsyncWrite};
use bytes::BytesMut;
use futures_core::{ready, Stream};
use futures_sink::Sink;
use log::trace;
use std::fmt;
use std::io::{self, Read};
use std::pin::Pin;
use std::task::{Context, Poll};
@@ -208,7 +209,7 @@ where
trace!("writing; remaining={}", pinned.buffer.len());
let buf = &pinned.buffer;
let n = try_ready!(pin!(pinned.inner).poll_write(cx, &buf));
let n = ready!(pin!(pinned.inner).poll_write(cx, &buf))?;
if n == 0 {
return Poll::Ready(Err(io::Error::new(
@@ -224,15 +225,16 @@ where
}
// Try flushing the underlying IO
try_ready!(pin!(pinned.inner).poll_flush(cx));
ready!(pin!(pinned.inner).poll_flush(cx))?;
trace!("framed transport flushed");
Poll::Ready(Ok(()))
}
fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
let () = try_ready!(pin!(self).poll_flush(cx));
let () = try_ready!(pin!(self.inner).poll_shutdown(cx));
ready!(pin!(self).poll_flush(cx))?;
ready!(pin!(self.inner).poll_shutdown(cx))?;
Poll::Ready(Ok(()))
}
}
-15
View File
@@ -1,18 +1,3 @@
// TODO this macro should probably be somewhere in tokio-futures
/// A macro for extracting the successful type of a `Poll<T, E>`.
///
/// This macro bakes propagation of both errors and `Pending` signals by
/// returning early.
macro_rules! try_ready {
($e:expr) => {
match $e {
std::task::Poll::Pending => return std::task::Poll::Pending,
std::task::Poll::Ready(Err(e)) => return std::task::Poll::Ready(Err(From::from(e))),
std::task::Poll::Ready(Ok(t)) => t,
}
};
}
/// A macro to reduce some of the boilerplate for projecting from
/// `Pin<&mut T>` to `Pin<&mut T.field>`
macro_rules! pin {