From 8d7d9451d0bfdb2a0df7344b7dc37365ba4195fe Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Sun, 19 Dec 2021 14:07:38 -0800 Subject: [PATCH] Make futures-util dependency optional --- quinn/Cargo.toml | 5 +++-- quinn/src/recv_stream.rs | 4 ++-- quinn/src/send_stream.rs | 12 ++++++------ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/quinn/Cargo.toml b/quinn/Cargo.toml index b799e9aa1..5702d11e5 100644 --- a/quinn/Cargo.toml +++ b/quinn/Cargo.toml @@ -14,7 +14,7 @@ edition = "2018" all-features = true [features] -default = ["native-certs", "tls-rustls", "ring"] +default = ["native-certs", "tls-rustls", "ring", "futures-util"] # Records how long locks are held, and warns if they are held >= 1ms lock_tracking = [] # Provides `ClientConfig::with_native_roots()` convenience method @@ -29,7 +29,8 @@ maintenance = { status = "experimental" } [dependencies] bytes = "1" -futures-util = { version = "0.3.11", default-features = false, features = ["io"] } +# Enables futures_util::io::{AsyncRead, AsyncWrite} support for streams +futures-util = { version = "0.3.11", default-features = false, features = ["io"], optional = true } futures-core = "0.3.19" futures-channel = "0.3.11" rustc-hash = "1.1" diff --git a/quinn/src/recv_stream.rs b/quinn/src/recv_stream.rs index 52dff3826..f99b5a22d 100644 --- a/quinn/src/recv_stream.rs +++ b/quinn/src/recv_stream.rs @@ -6,7 +6,6 @@ use std::{ }; use bytes::Bytes; -use futures_util::io::AsyncRead; use proto::{Chunk, Chunks, ConnectionError, ReadableError, StreamId}; use thiserror::Error; use tokio::io::ReadBuf; @@ -355,7 +354,8 @@ pub enum ReadToEndError { TooLong, } -impl AsyncRead for RecvStream { +#[cfg(feature = "futures-util")] +impl futures_util::io::AsyncRead for RecvStream { fn poll_read( self: Pin<&mut Self>, cx: &mut Context, diff --git a/quinn/src/send_stream.rs b/quinn/src/send_stream.rs index c0905f4ae..b979ef559 100644 --- a/quinn/src/send_stream.rs +++ b/quinn/src/send_stream.rs @@ -7,7 +7,6 @@ use std::{ use bytes::Bytes; use futures_channel::oneshot; -use futures_util::io::AsyncWrite; use proto::{ConnectionError, FinishError, StreamId, Written}; use thiserror::Error; @@ -220,9 +219,10 @@ impl SendStream { } } -impl AsyncWrite for SendStream { +#[cfg(feature = "futures-util")] +impl futures_util::io::AsyncWrite for SendStream { fn poll_write(self: Pin<&mut Self>, cx: &mut Context, buf: &[u8]) -> Poll> { - SendStream::execute_poll(self.get_mut(), cx, |stream| stream.write(buf)).map_err(Into::into) + tokio::io::AsyncWrite::poll_write(self, cx, buf) } fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context) -> Poll> { @@ -230,7 +230,7 @@ impl AsyncWrite for SendStream { } fn poll_close(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { - self.get_mut().poll_finish(cx).map_err(Into::into) + tokio::io::AsyncWrite::poll_shutdown(self, cx) } } @@ -240,7 +240,7 @@ impl tokio::io::AsyncWrite for SendStream { cx: &mut Context<'_>, buf: &[u8], ) -> Poll> { - AsyncWrite::poll_write(self, cx, buf) + SendStream::execute_poll(self.get_mut(), cx, |stream| stream.write(buf)).map_err(Into::into) } fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context) -> Poll> { @@ -248,7 +248,7 @@ impl tokio::io::AsyncWrite for SendStream { } fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { - AsyncWrite::poll_close(self, cx) + self.get_mut().poll_finish(cx).map_err(Into::into) } }