From 4441372121e8b278ac773ddd4e408a642dadf2d8 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Wed, 10 Jul 2019 16:41:44 -0700 Subject: [PATCH] feat(body): require `Sync` when wrapping a dynamic `Stream` --- src/body/body.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/body/body.rs b/src/body/body.rs index a72a6fab95..44214757b8 100644 --- a/src/body/body.rs +++ b/src/body/body.rs @@ -41,7 +41,11 @@ enum Kind { content_length: Option, recv: h2::RecvStream, }, - Wrapped(Pin>> + Send>>), + // NOTE: This requires `Sync` because of how easy it is to use `await` + // while a borrow of a `Request` exists. + // + // See https://github.com/rust-lang/rust/issues/57017 + Wrapped(Pin>> + Send + Sync>>), } struct Extra { @@ -142,7 +146,7 @@ impl Body { /// ``` pub fn wrap_stream(stream: S) -> Body where - S: TryStream + Send + 'static, + S: TryStream + Send + Sync + 'static, S::Error: Into>, Chunk: From, { @@ -411,13 +415,13 @@ impl Stream for Body { impl - From>> + Send>> + From>> + Send + Sync>> for Body { #[inline] fn from( stream: Box< - dyn Stream>> + Send, + dyn Stream>> + Send + Sync, >, ) -> Body { Body::new(Kind::Wrapped(stream.into()))