From ec751f3696882889e65a00c234da70e5254a8048 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Fri, 6 Dec 2019 11:26:36 -0800 Subject: [PATCH] Remove Unpin requirement for the send Buf --- src/client.rs | 10 +++++----- src/codec/framed_write.rs | 5 ++++- src/codec/mod.rs | 7 +++---- src/proto/connection.rs | 4 ++-- src/proto/go_away.rs | 2 +- src/proto/ping_pong.rs | 4 ++-- src/proto/settings.rs | 8 ++++---- src/proto/streams/prioritize.rs | 2 +- src/proto/streams/recv.rs | 8 ++++---- src/proto/streams/send.rs | 2 +- src/proto/streams/streams.rs | 3 +-- src/server.rs | 12 ++++++------ 12 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/client.rs b/src/client.rs index f09b786..63514e3 100644 --- a/src/client.rs +++ b/src/client.rs @@ -336,7 +336,7 @@ pub(crate) struct Peer; impl SendRequest where - B: Buf + Unpin + 'static, + B: Buf + 'static, { /// Returns `Ready` when the connection can initialize a new HTTP/2.0 /// stream. @@ -566,7 +566,7 @@ where impl Future for ReadySendRequest where - B: Buf + Unpin + 'static, + B: Buf + 'static, { type Output = Result, crate::Error>; @@ -1063,7 +1063,7 @@ impl Builder { ) -> impl Future, Connection), crate::Error>> where T: AsyncRead + AsyncWrite + Unpin, - B: Buf + Unpin + 'static, + B: Buf + 'static, { Connection::handshake2(io, self.clone()) } @@ -1123,7 +1123,7 @@ where impl Connection where T: AsyncRead + AsyncWrite + Unpin, - B: Buf + Unpin + 'static, + B: Buf + 'static, { async fn handshake2( mut io: T, @@ -1229,7 +1229,7 @@ where impl Future for Connection where T: AsyncRead + AsyncWrite + Unpin, - B: Buf + Unpin + 'static, + B: Buf + 'static, { type Output = Result<(), crate::Error>; diff --git a/src/codec/framed_write.rs b/src/codec/framed_write.rs index 072e471..b9a06c6 100644 --- a/src/codec/framed_write.rs +++ b/src/codec/framed_write.rs @@ -281,7 +281,7 @@ impl FramedWrite { } } -impl AsyncRead for FramedWrite { +impl AsyncRead for FramedWrite { unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [std::mem::MaybeUninit]) -> bool { self.inner.prepare_uninitialized_buffer(buf) } @@ -303,6 +303,9 @@ impl AsyncRead for FramedWrite { } } +// We never project the Pin to `B`. +impl Unpin for FramedWrite {} + #[cfg(feature = "unstable")] mod unstable { use super::*; diff --git a/src/codec/mod.rs b/src/codec/mod.rs index 3ed65bb..9bd4e73 100644 --- a/src/codec/mod.rs +++ b/src/codec/mod.rs @@ -27,7 +27,7 @@ pub struct Codec { impl Codec where T: AsyncRead + AsyncWrite + Unpin, - B: Buf + Unpin, + B: Buf, { /// Returns a new `Codec` with the default max frame size #[inline] @@ -118,7 +118,7 @@ impl Codec { impl Codec where T: AsyncWrite + Unpin, - B: Buf + Unpin, + B: Buf, { /// Returns `Ready` when the codec can buffer a frame pub fn poll_ready(&mut self, cx: &mut Context) -> Poll> { @@ -149,7 +149,6 @@ where impl Stream for Codec where T: AsyncRead + Unpin, - B: Unpin, { type Item = Result; @@ -161,7 +160,7 @@ where impl Sink> for Codec where T: AsyncWrite + Unpin, - B: Buf + Unpin, + B: Buf, { type Error = SendError; diff --git a/src/proto/connection.rs b/src/proto/connection.rs index 8a6f34c..49c123e 100644 --- a/src/proto/connection.rs +++ b/src/proto/connection.rs @@ -73,7 +73,7 @@ impl Connection where T: AsyncRead + AsyncWrite + Unpin, P: Peer, - B: Buf + Unpin, + B: Buf, { pub fn new(codec: Codec>, config: Config) -> Connection { let streams = Streams::new(streams::Config { @@ -394,7 +394,7 @@ where impl Connection where T: AsyncRead + AsyncWrite + Unpin, - B: Buf + Unpin, + B: Buf, { pub fn next_incoming(&mut self) -> Option> { self.streams.next_incoming() diff --git a/src/proto/go_away.rs b/src/proto/go_away.rs index 3d934b5..91d37b6 100644 --- a/src/proto/go_away.rs +++ b/src/proto/go_away.rs @@ -128,7 +128,7 @@ impl GoAway { ) -> Poll>> where T: AsyncWrite + Unpin, - B: Buf + Unpin, + B: Buf, { if let Some(frame) = self.pending.take() { if !dst.poll_ready(cx)?.is_ready() { diff --git a/src/proto/ping_pong.rs b/src/proto/ping_pong.rs index 43cd2d7..0022d4a 100644 --- a/src/proto/ping_pong.rs +++ b/src/proto/ping_pong.rs @@ -142,7 +142,7 @@ impl PingPong { ) -> Poll> where T: AsyncWrite + Unpin, - B: Buf + Unpin, + B: Buf, { if let Some(pong) = self.pending_pong.take() { if !dst.poll_ready(cx)?.is_ready() { @@ -165,7 +165,7 @@ impl PingPong { ) -> Poll> where T: AsyncWrite + Unpin, - B: Buf + Unpin, + B: Buf, { if let Some(ref mut ping) = self.pending_ping { if !ping.sent { diff --git a/src/proto/settings.rs b/src/proto/settings.rs index 46bb3f6..014dbf7 100644 --- a/src/proto/settings.rs +++ b/src/proto/settings.rs @@ -43,8 +43,8 @@ impl Settings { ) -> Result<(), RecvError> where T: AsyncWrite + Unpin, - B: Buf + Unpin, - C: Buf + Unpin, + B: Buf, + C: Buf, P: Peer, { if frame.is_ack() { @@ -100,8 +100,8 @@ impl Settings { ) -> Poll> where T: AsyncWrite + Unpin, - B: Buf + Unpin, - C: Buf + Unpin, + B: Buf, + C: Buf, P: Peer, { if let Some(settings) = &self.remote { diff --git a/src/proto/streams/prioritize.rs b/src/proto/streams/prioritize.rs index ddaec8f..a133932 100644 --- a/src/proto/streams/prioritize.rs +++ b/src/proto/streams/prioritize.rs @@ -474,7 +474,7 @@ impl Prioritize { ) -> Poll> where T: AsyncWrite + Unpin, - B: Buf + Unpin, + B: Buf, { // Ensure codec is ready ready!(dst.poll_ready(cx))?; diff --git a/src/proto/streams/recv.rs b/src/proto/streams/recv.rs index ac2120c..f0e23a4 100644 --- a/src/proto/streams/recv.rs +++ b/src/proto/streams/recv.rs @@ -846,7 +846,7 @@ impl Recv { ) -> Poll> where T: AsyncWrite + Unpin, - B: Buf + Unpin, + B: Buf, { if let Some(stream_id) = self.refused { ready!(dst.poll_ready(cx))?; @@ -918,7 +918,7 @@ impl Recv { ) -> Poll> where T: AsyncWrite + Unpin, - B: Buf + Unpin, + B: Buf, { // Send any pending connection level window updates ready!(self.send_connection_window_update(cx, dst))?; @@ -937,7 +937,7 @@ impl Recv { ) -> Poll> where T: AsyncWrite + Unpin, - B: Buf + Unpin, + B: Buf, { if let Some(incr) = self.flow.unclaimed_capacity() { let frame = frame::WindowUpdate::new(StreamId::zero(), incr); @@ -968,7 +968,7 @@ impl Recv { ) -> Poll> where T: AsyncWrite + Unpin, - B: Buf + Unpin, + B: Buf, { loop { // Ensure the codec has capacity diff --git a/src/proto/streams/send.rs b/src/proto/streams/send.rs index 33aa443..a1199b2 100644 --- a/src/proto/streams/send.rs +++ b/src/proto/streams/send.rs @@ -279,7 +279,7 @@ impl Send { ) -> Poll> where T: AsyncWrite + Unpin, - B: Buf + Unpin, + B: Buf, { self.prioritize .poll_complete(cx, buffer, store, counts, dst) diff --git a/src/proto/streams/streams.rs b/src/proto/streams/streams.rs index 49bbe71..527969b 100644 --- a/src/proto/streams/streams.rs +++ b/src/proto/streams/streams.rs @@ -94,7 +94,7 @@ struct SendBuffer { impl Streams where - B: Buf + Unpin, + B: Buf, P: Peer, { pub fn new(config: Config) -> Self { @@ -596,7 +596,6 @@ where ) -> Poll> where T: AsyncWrite + Unpin, - B: Unpin, { let mut me = self.inner.lock().unwrap(); let me = &mut *me; diff --git a/src/server.rs b/src/server.rs index e99abe0..513a975 100644 --- a/src/server.rs +++ b/src/server.rs @@ -356,7 +356,7 @@ where impl Connection where T: AsyncRead + AsyncWrite + Unpin, - B: Buf + Unpin + 'static, + B: Buf + 'static, { fn handshake2(io: T, builder: Builder) -> Handshake { // Create the codec. @@ -523,7 +523,7 @@ where impl futures_core::Stream for Connection where T: AsyncRead + AsyncWrite + Unpin, - B: Buf + Unpin + 'static, + B: Buf + 'static, { type Item = Result<(Request, SendResponse), crate::Error>; @@ -921,7 +921,7 @@ impl Builder { pub fn handshake(&self, io: T) -> Handshake where T: AsyncRead + AsyncWrite + Unpin, - B: Buf + Unpin + 'static, + B: Buf + 'static, { Connection::handshake2(io, self.clone()) } @@ -1108,7 +1108,7 @@ impl Flush { impl Future for Flush where T: AsyncWrite + Unpin, - B: Buf + Unpin, + B: Buf, { type Output = Result, crate::Error>; @@ -1137,7 +1137,7 @@ impl ReadPreface { impl Future for ReadPreface where T: AsyncRead + Unpin, - B: Buf + Unpin, + B: Buf, { type Output = Result, crate::Error>; @@ -1174,7 +1174,7 @@ where impl Future for Handshake where T: AsyncRead + AsyncWrite + Unpin, - B: Buf + Unpin + 'static, + B: Buf + 'static, { type Output = Result, crate::Error>;