Remove Unpin requirement for the send Buf

This commit is contained in:
Sean McArthur
2019-12-06 11:26:36 -08:00
parent 13e0f17a03
commit ec751f3696
12 changed files with 34 additions and 33 deletions

View File

@@ -336,7 +336,7 @@ pub(crate) struct Peer;
impl<B> SendRequest<B> impl<B> SendRequest<B>
where where
B: Buf + Unpin + 'static, B: Buf + 'static,
{ {
/// Returns `Ready` when the connection can initialize a new HTTP/2.0 /// Returns `Ready` when the connection can initialize a new HTTP/2.0
/// stream. /// stream.
@@ -566,7 +566,7 @@ where
impl<B> Future for ReadySendRequest<B> impl<B> Future for ReadySendRequest<B>
where where
B: Buf + Unpin + 'static, B: Buf + 'static,
{ {
type Output = Result<SendRequest<B>, crate::Error>; type Output = Result<SendRequest<B>, crate::Error>;
@@ -1063,7 +1063,7 @@ impl Builder {
) -> impl Future<Output = Result<(SendRequest<B>, Connection<T, B>), crate::Error>> ) -> impl Future<Output = Result<(SendRequest<B>, Connection<T, B>), crate::Error>>
where where
T: AsyncRead + AsyncWrite + Unpin, T: AsyncRead + AsyncWrite + Unpin,
B: Buf + Unpin + 'static, B: Buf + 'static,
{ {
Connection::handshake2(io, self.clone()) Connection::handshake2(io, self.clone())
} }
@@ -1123,7 +1123,7 @@ where
impl<T, B> Connection<T, B> impl<T, B> Connection<T, B>
where where
T: AsyncRead + AsyncWrite + Unpin, T: AsyncRead + AsyncWrite + Unpin,
B: Buf + Unpin + 'static, B: Buf + 'static,
{ {
async fn handshake2( async fn handshake2(
mut io: T, mut io: T,
@@ -1229,7 +1229,7 @@ where
impl<T, B> Future for Connection<T, B> impl<T, B> Future for Connection<T, B>
where where
T: AsyncRead + AsyncWrite + Unpin, T: AsyncRead + AsyncWrite + Unpin,
B: Buf + Unpin + 'static, B: Buf + 'static,
{ {
type Output = Result<(), crate::Error>; type Output = Result<(), crate::Error>;

View File

@@ -281,7 +281,7 @@ impl<T, B> FramedWrite<T, B> {
} }
} }
impl<T: AsyncRead + Unpin, B: Unpin> AsyncRead for FramedWrite<T, B> { impl<T: AsyncRead + Unpin, B> AsyncRead for FramedWrite<T, B> {
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [std::mem::MaybeUninit<u8>]) -> bool { unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [std::mem::MaybeUninit<u8>]) -> bool {
self.inner.prepare_uninitialized_buffer(buf) self.inner.prepare_uninitialized_buffer(buf)
} }
@@ -303,6 +303,9 @@ impl<T: AsyncRead + Unpin, B: Unpin> AsyncRead for FramedWrite<T, B> {
} }
} }
// We never project the Pin to `B`.
impl<T: Unpin, B> Unpin for FramedWrite<T, B> {}
#[cfg(feature = "unstable")] #[cfg(feature = "unstable")]
mod unstable { mod unstable {
use super::*; use super::*;

View File

@@ -27,7 +27,7 @@ pub struct Codec<T, B> {
impl<T, B> Codec<T, B> impl<T, B> Codec<T, B>
where where
T: AsyncRead + AsyncWrite + Unpin, T: AsyncRead + AsyncWrite + Unpin,
B: Buf + Unpin, B: Buf,
{ {
/// Returns a new `Codec` with the default max frame size /// Returns a new `Codec` with the default max frame size
#[inline] #[inline]
@@ -118,7 +118,7 @@ impl<T, B> Codec<T, B> {
impl<T, B> Codec<T, B> impl<T, B> Codec<T, B>
where where
T: AsyncWrite + Unpin, T: AsyncWrite + Unpin,
B: Buf + Unpin, B: Buf,
{ {
/// Returns `Ready` when the codec can buffer a frame /// Returns `Ready` when the codec can buffer a frame
pub fn poll_ready(&mut self, cx: &mut Context) -> Poll<io::Result<()>> { pub fn poll_ready(&mut self, cx: &mut Context) -> Poll<io::Result<()>> {
@@ -149,7 +149,6 @@ where
impl<T, B> Stream for Codec<T, B> impl<T, B> Stream for Codec<T, B>
where where
T: AsyncRead + Unpin, T: AsyncRead + Unpin,
B: Unpin,
{ {
type Item = Result<Frame, RecvError>; type Item = Result<Frame, RecvError>;
@@ -161,7 +160,7 @@ where
impl<T, B> Sink<Frame<B>> for Codec<T, B> impl<T, B> Sink<Frame<B>> for Codec<T, B>
where where
T: AsyncWrite + Unpin, T: AsyncWrite + Unpin,
B: Buf + Unpin, B: Buf,
{ {
type Error = SendError; type Error = SendError;

View File

@@ -73,7 +73,7 @@ impl<T, P, B> Connection<T, P, B>
where where
T: AsyncRead + AsyncWrite + Unpin, T: AsyncRead + AsyncWrite + Unpin,
P: Peer, P: Peer,
B: Buf + Unpin, B: Buf,
{ {
pub fn new(codec: Codec<T, Prioritized<B>>, config: Config) -> Connection<T, P, B> { pub fn new(codec: Codec<T, Prioritized<B>>, config: Config) -> Connection<T, P, B> {
let streams = Streams::new(streams::Config { let streams = Streams::new(streams::Config {
@@ -394,7 +394,7 @@ where
impl<T, B> Connection<T, server::Peer, B> impl<T, B> Connection<T, server::Peer, B>
where where
T: AsyncRead + AsyncWrite + Unpin, T: AsyncRead + AsyncWrite + Unpin,
B: Buf + Unpin, B: Buf,
{ {
pub fn next_incoming(&mut self) -> Option<StreamRef<B>> { pub fn next_incoming(&mut self) -> Option<StreamRef<B>> {
self.streams.next_incoming() self.streams.next_incoming()

View File

@@ -128,7 +128,7 @@ impl GoAway {
) -> Poll<Option<io::Result<Reason>>> ) -> Poll<Option<io::Result<Reason>>>
where where
T: AsyncWrite + Unpin, T: AsyncWrite + Unpin,
B: Buf + Unpin, B: Buf,
{ {
if let Some(frame) = self.pending.take() { if let Some(frame) = self.pending.take() {
if !dst.poll_ready(cx)?.is_ready() { if !dst.poll_ready(cx)?.is_ready() {

View File

@@ -142,7 +142,7 @@ impl PingPong {
) -> Poll<io::Result<()>> ) -> Poll<io::Result<()>>
where where
T: AsyncWrite + Unpin, T: AsyncWrite + Unpin,
B: Buf + Unpin, B: Buf,
{ {
if let Some(pong) = self.pending_pong.take() { if let Some(pong) = self.pending_pong.take() {
if !dst.poll_ready(cx)?.is_ready() { if !dst.poll_ready(cx)?.is_ready() {
@@ -165,7 +165,7 @@ impl PingPong {
) -> Poll<io::Result<()>> ) -> Poll<io::Result<()>>
where where
T: AsyncWrite + Unpin, T: AsyncWrite + Unpin,
B: Buf + Unpin, B: Buf,
{ {
if let Some(ref mut ping) = self.pending_ping { if let Some(ref mut ping) = self.pending_ping {
if !ping.sent { if !ping.sent {

View File

@@ -43,8 +43,8 @@ impl Settings {
) -> Result<(), RecvError> ) -> Result<(), RecvError>
where where
T: AsyncWrite + Unpin, T: AsyncWrite + Unpin,
B: Buf + Unpin, B: Buf,
C: Buf + Unpin, C: Buf,
P: Peer, P: Peer,
{ {
if frame.is_ack() { if frame.is_ack() {
@@ -100,8 +100,8 @@ impl Settings {
) -> Poll<Result<(), RecvError>> ) -> Poll<Result<(), RecvError>>
where where
T: AsyncWrite + Unpin, T: AsyncWrite + Unpin,
B: Buf + Unpin, B: Buf,
C: Buf + Unpin, C: Buf,
P: Peer, P: Peer,
{ {
if let Some(settings) = &self.remote { if let Some(settings) = &self.remote {

View File

@@ -474,7 +474,7 @@ impl Prioritize {
) -> Poll<io::Result<()>> ) -> Poll<io::Result<()>>
where where
T: AsyncWrite + Unpin, T: AsyncWrite + Unpin,
B: Buf + Unpin, B: Buf,
{ {
// Ensure codec is ready // Ensure codec is ready
ready!(dst.poll_ready(cx))?; ready!(dst.poll_ready(cx))?;

View File

@@ -846,7 +846,7 @@ impl Recv {
) -> Poll<io::Result<()>> ) -> Poll<io::Result<()>>
where where
T: AsyncWrite + Unpin, T: AsyncWrite + Unpin,
B: Buf + Unpin, B: Buf,
{ {
if let Some(stream_id) = self.refused { if let Some(stream_id) = self.refused {
ready!(dst.poll_ready(cx))?; ready!(dst.poll_ready(cx))?;
@@ -918,7 +918,7 @@ impl Recv {
) -> Poll<io::Result<()>> ) -> Poll<io::Result<()>>
where where
T: AsyncWrite + Unpin, T: AsyncWrite + Unpin,
B: Buf + Unpin, B: Buf,
{ {
// Send any pending connection level window updates // Send any pending connection level window updates
ready!(self.send_connection_window_update(cx, dst))?; ready!(self.send_connection_window_update(cx, dst))?;
@@ -937,7 +937,7 @@ impl Recv {
) -> Poll<io::Result<()>> ) -> Poll<io::Result<()>>
where where
T: AsyncWrite + Unpin, T: AsyncWrite + Unpin,
B: Buf + Unpin, B: Buf,
{ {
if let Some(incr) = self.flow.unclaimed_capacity() { if let Some(incr) = self.flow.unclaimed_capacity() {
let frame = frame::WindowUpdate::new(StreamId::zero(), incr); let frame = frame::WindowUpdate::new(StreamId::zero(), incr);
@@ -968,7 +968,7 @@ impl Recv {
) -> Poll<io::Result<()>> ) -> Poll<io::Result<()>>
where where
T: AsyncWrite + Unpin, T: AsyncWrite + Unpin,
B: Buf + Unpin, B: Buf,
{ {
loop { loop {
// Ensure the codec has capacity // Ensure the codec has capacity

View File

@@ -279,7 +279,7 @@ impl Send {
) -> Poll<io::Result<()>> ) -> Poll<io::Result<()>>
where where
T: AsyncWrite + Unpin, T: AsyncWrite + Unpin,
B: Buf + Unpin, B: Buf,
{ {
self.prioritize self.prioritize
.poll_complete(cx, buffer, store, counts, dst) .poll_complete(cx, buffer, store, counts, dst)

View File

@@ -94,7 +94,7 @@ struct SendBuffer<B> {
impl<B, P> Streams<B, P> impl<B, P> Streams<B, P>
where where
B: Buf + Unpin, B: Buf,
P: Peer, P: Peer,
{ {
pub fn new(config: Config) -> Self { pub fn new(config: Config) -> Self {
@@ -596,7 +596,6 @@ where
) -> Poll<io::Result<()>> ) -> Poll<io::Result<()>>
where where
T: AsyncWrite + Unpin, T: AsyncWrite + Unpin,
B: Unpin,
{ {
let mut me = self.inner.lock().unwrap(); let mut me = self.inner.lock().unwrap();
let me = &mut *me; let me = &mut *me;

View File

@@ -356,7 +356,7 @@ where
impl<T, B> Connection<T, B> impl<T, B> Connection<T, B>
where where
T: AsyncRead + AsyncWrite + Unpin, T: AsyncRead + AsyncWrite + Unpin,
B: Buf + Unpin + 'static, B: Buf + 'static,
{ {
fn handshake2(io: T, builder: Builder) -> Handshake<T, B> { fn handshake2(io: T, builder: Builder) -> Handshake<T, B> {
// Create the codec. // Create the codec.
@@ -523,7 +523,7 @@ where
impl<T, B> futures_core::Stream for Connection<T, B> impl<T, B> futures_core::Stream for Connection<T, B>
where where
T: AsyncRead + AsyncWrite + Unpin, T: AsyncRead + AsyncWrite + Unpin,
B: Buf + Unpin + 'static, B: Buf + 'static,
{ {
type Item = Result<(Request<RecvStream>, SendResponse<B>), crate::Error>; type Item = Result<(Request<RecvStream>, SendResponse<B>), crate::Error>;
@@ -921,7 +921,7 @@ impl Builder {
pub fn handshake<T, B>(&self, io: T) -> Handshake<T, B> pub fn handshake<T, B>(&self, io: T) -> Handshake<T, B>
where where
T: AsyncRead + AsyncWrite + Unpin, T: AsyncRead + AsyncWrite + Unpin,
B: Buf + Unpin + 'static, B: Buf + 'static,
{ {
Connection::handshake2(io, self.clone()) Connection::handshake2(io, self.clone())
} }
@@ -1108,7 +1108,7 @@ impl<T, B: Buf> Flush<T, B> {
impl<T, B> Future for Flush<T, B> impl<T, B> Future for Flush<T, B>
where where
T: AsyncWrite + Unpin, T: AsyncWrite + Unpin,
B: Buf + Unpin, B: Buf,
{ {
type Output = Result<Codec<T, B>, crate::Error>; type Output = Result<Codec<T, B>, crate::Error>;
@@ -1137,7 +1137,7 @@ impl<T, B: Buf> ReadPreface<T, B> {
impl<T, B> Future for ReadPreface<T, B> impl<T, B> Future for ReadPreface<T, B>
where where
T: AsyncRead + Unpin, T: AsyncRead + Unpin,
B: Buf + Unpin, B: Buf,
{ {
type Output = Result<Codec<T, B>, crate::Error>; type Output = Result<Codec<T, B>, crate::Error>;
@@ -1174,7 +1174,7 @@ where
impl<T, B: Buf> Future for Handshake<T, B> impl<T, B: Buf> Future for Handshake<T, B>
where where
T: AsyncRead + AsyncWrite + Unpin, T: AsyncRead + AsyncWrite + Unpin,
B: Buf + Unpin + 'static, B: Buf + 'static,
{ {
type Output = Result<Connection<T, B>, crate::Error>; type Output = Result<Connection<T, B>, crate::Error>;