|
| 1 | +use bytes::{Buf, IntoBuf}; |
1 | 2 | use futures::sink; |
2 | 3 | use futures::sync::mpsc; |
3 | 4 | use futures::{Async, AsyncSink, Future, Poll, Sink, Stream}; |
@@ -63,7 +64,8 @@ impl Stream for CopyInReceiver { |
63 | 64 | pub enum CopyIn<S> |
64 | 65 | where |
65 | 66 | S: Stream, |
66 | | - S::Item: AsRef<[u8]>, |
| 67 | + S::Item: IntoBuf, |
| 68 | + <S::Item as IntoBuf>::Buf: Send, |
67 | 69 | S::Error: Into<Box<StdError + Sync + Send>>, |
68 | 70 | { |
69 | 71 | #[state_machine_future(start, transitions(ReadCopyInResponse))] |
@@ -103,7 +105,8 @@ where |
103 | 105 | impl<S> PollCopyIn<S> for CopyIn<S> |
104 | 106 | where |
105 | 107 | S: Stream, |
106 | | - S::Item: AsRef<[u8]>, |
| 108 | + S::Item: IntoBuf, |
| 109 | + <S::Item as IntoBuf>::Buf: Send, |
107 | 110 | S::Error: Into<Box<StdError + Sync + Send>>, |
108 | 111 | { |
109 | 112 | fn poll_start<'a>(state: &'a mut RentToOwn<'a, Start<S>>) -> Poll<AfterStart<S>, Error> { |
@@ -151,7 +154,9 @@ where |
151 | 154 | None => match try_ready!(state.stream.poll().map_err(Error::copy_in_stream)) { |
152 | 155 | Some(data) => { |
153 | 156 | let mut buf = vec![]; |
154 | | - frontend::copy_data(data.as_ref(), &mut buf).map_err(Error::encode)?; |
| 157 | + // FIXME avoid collect |
| 158 | + frontend::copy_data(&data.into_buf().collect::<Vec<_>>(), &mut buf) |
| 159 | + .map_err(Error::encode)?; |
155 | 160 | CopyMessage::Data(buf) |
156 | 161 | } |
157 | 162 | None => { |
@@ -213,7 +218,8 @@ where |
213 | 218 | impl<S> CopyInFuture<S> |
214 | 219 | where |
215 | 220 | S: Stream, |
216 | | - S::Item: AsRef<[u8]>, |
| 221 | + S::Item: IntoBuf, |
| 222 | + <S::Item as IntoBuf>::Buf: Send, |
217 | 223 | S::Error: Into<Box<StdError + Sync + Send>>, |
218 | 224 | { |
219 | 225 | pub fn new( |
|
0 commit comments