Make copy_in stream more flexible

This commit is contained in:
Steven Fackler
2018-08-12 21:23:21 -06:00
parent bfd2c7f436
commit 3d22aa323b
3 changed files with 13 additions and 7 deletions

View File

@@ -99,7 +99,8 @@ impl Client {
pub fn copy_in<S>(&mut self, statement: &Statement, params: &[&ToSql], stream: S) -> CopyIn<S>
where
S: Stream<Item = Vec<u8>>,
S: Stream,
S::Item: AsRef<[u8]>,
S::Error: Into<Box<StdError + Sync + Send>>,
{
CopyIn(self.0.copy_in(&statement.0, params, stream))
@@ -239,7 +240,8 @@ impl Stream for Query {
#[must_use = "futures do nothing unless polled"]
pub struct CopyIn<S>(proto::CopyInFuture<S>)
where
S: Stream<Item = Vec<u8>>,
S: Stream,
S::Item: AsRef<[u8]>,
S::Error: Into<Box<StdError + Sync + Send>>;
impl<S> Future for CopyIn<S>

View File

@@ -142,7 +142,8 @@ impl Client {
pub fn copy_in<S>(&self, statement: &Statement, params: &[&ToSql], stream: S) -> CopyInFuture<S>
where
S: Stream<Item = Vec<u8>>,
S: Stream,
S::Item: AsRef<[u8]>,
S::Error: Into<Box<StdError + Sync + Send>>,
{
let (mut sender, receiver) = mpsc::channel(0);

View File

@@ -63,7 +63,8 @@ impl Stream for CopyInReceiver {
#[derive(StateMachineFuture)]
pub enum CopyIn<S>
where
S: Stream<Item = Vec<u8>>,
S: Stream,
S::Item: AsRef<[u8]>,
S::Error: Into<Box<StdError + Sync + Send>>,
{
#[state_machine_future(start, transitions(ReadCopyInResponse))]
@@ -102,7 +103,8 @@ where
impl<S> PollCopyIn<S> for CopyIn<S>
where
S: Stream<Item = Vec<u8>>,
S: Stream,
S::Item: AsRef<[u8]>,
S::Error: Into<Box<StdError + Sync + Send>>,
{
fn poll_start<'a>(state: &'a mut RentToOwn<'a, Start<S>>) -> Poll<AfterStart<S>, Error> {
@@ -150,7 +152,7 @@ where
None => match try_ready!(state.stream.poll().map_err(error::__user)) {
Some(data) => {
let mut buf = vec![];
frontend::copy_data(&data, &mut buf).map_err(error::io)?;
frontend::copy_data(data.as_ref(), &mut buf).map_err(error::io)?;
CopyMessage::Data(buf)
}
None => {
@@ -204,7 +206,8 @@ where
impl<S> CopyInFuture<S>
where
S: Stream<Item = Vec<u8>>,
S: Stream,
S::Item: AsRef<[u8]>,
S::Error: Into<Box<StdError + Sync + Send>>,
{
pub fn new(