Skip to content

Commit 3d22aa3

Browse files
committed
Make copy_in stream more flexible
1 parent bfd2c7f commit 3d22aa3

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

tokio-postgres/src/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ impl Client {
9999

100100
pub fn copy_in<S>(&mut self, statement: &Statement, params: &[&ToSql], stream: S) -> CopyIn<S>
101101
where
102-
S: Stream<Item = Vec<u8>>,
102+
S: Stream,
103+
S::Item: AsRef<[u8]>,
103104
S::Error: Into<Box<StdError + Sync + Send>>,
104105
{
105106
CopyIn(self.0.copy_in(&statement.0, params, stream))
@@ -239,7 +240,8 @@ impl Stream for Query {
239240
#[must_use = "futures do nothing unless polled"]
240241
pub struct CopyIn<S>(proto::CopyInFuture<S>)
241242
where
242-
S: Stream<Item = Vec<u8>>,
243+
S: Stream,
244+
S::Item: AsRef<[u8]>,
243245
S::Error: Into<Box<StdError + Sync + Send>>;
244246

245247
impl<S> Future for CopyIn<S>

tokio-postgres/src/proto/client.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ impl Client {
142142

143143
pub fn copy_in<S>(&self, statement: &Statement, params: &[&ToSql], stream: S) -> CopyInFuture<S>
144144
where
145-
S: Stream<Item = Vec<u8>>,
145+
S: Stream,
146+
S::Item: AsRef<[u8]>,
146147
S::Error: Into<Box<StdError + Sync + Send>>,
147148
{
148149
let (mut sender, receiver) = mpsc::channel(0);

tokio-postgres/src/proto/copy_in.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ impl Stream for CopyInReceiver {
6363
#[derive(StateMachineFuture)]
6464
pub enum CopyIn<S>
6565
where
66-
S: Stream<Item = Vec<u8>>,
66+
S: Stream,
67+
S::Item: AsRef<[u8]>,
6768
S::Error: Into<Box<StdError + Sync + Send>>,
6869
{
6970
#[state_machine_future(start, transitions(ReadCopyInResponse))]
@@ -102,7 +103,8 @@ where
102103

103104
impl<S> PollCopyIn<S> for CopyIn<S>
104105
where
105-
S: Stream<Item = Vec<u8>>,
106+
S: Stream,
107+
S::Item: AsRef<[u8]>,
106108
S::Error: Into<Box<StdError + Sync + Send>>,
107109
{
108110
fn poll_start<'a>(state: &'a mut RentToOwn<'a, Start<S>>) -> Poll<AfterStart<S>, Error> {
@@ -150,7 +152,7 @@ where
150152
None => match try_ready!(state.stream.poll().map_err(error::__user)) {
151153
Some(data) => {
152154
let mut buf = vec![];
153-
frontend::copy_data(&data, &mut buf).map_err(error::io)?;
155+
frontend::copy_data(data.as_ref(), &mut buf).map_err(error::io)?;
154156
CopyMessage::Data(buf)
155157
}
156158
None => {
@@ -204,7 +206,8 @@ where
204206

205207
impl<S> CopyInFuture<S>
206208
where
207-
S: Stream<Item = Vec<u8>>,
209+
S: Stream,
210+
S::Item: AsRef<[u8]>,
208211
S::Error: Into<Box<StdError + Sync + Send>>,
209212
{
210213
pub fn new(

0 commit comments

Comments
 (0)