From 6de2fb038c6ed7b50e19fd11705a3c0be0600821 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 20 Sep 2016 16:58:04 -0400 Subject: [PATCH] write_message2 -> write_message --- src/lib.rs | 34 +++++++++++++++++----------------- src/priv_io.rs | 2 +- src/rows.rs | 4 ++-- src/stmt.rs | 24 +++++++++++++----------- 4 files changed, 33 insertions(+), 31 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6c85f6d1..9e63a779 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -274,7 +274,7 @@ impl InnerConnection { } let options = options.iter().map(|&(ref a, ref b)| (&**a, &**b)); - try!(conn.stream.write_message2(|buf| frontend::startup_message(options, buf))); + try!(conn.stream.write_message(|buf| frontend::startup_message(options, buf))); try!(conn.stream.flush()); try!(conn.handle_auth(user)); @@ -370,7 +370,7 @@ impl InnerConnection { let pass = try!(user.password.ok_or_else(|| { ConnectError::ConnectParams("a password was requested but not provided".into()) })); - try!(self.stream.write_message2(|buf| frontend::password_message(&pass, buf))); + try!(self.stream.write_message(|buf| frontend::password_message(&pass, buf))); try!(self.stream.flush()); } backend::Message::AuthenticationMD5Password { salt } => { @@ -378,7 +378,7 @@ impl InnerConnection { ConnectError::ConnectParams("a password was requested but not provided".into()) })); let output = authentication::md5_hash(user.user.as_bytes(), pass.as_bytes(), salt); - try!(self.stream.write_message2(|buf| frontend::password_message(&output, buf))); + try!(self.stream.write_message(|buf| frontend::password_message(&output, buf))); try!(self.stream.flush()); } backend::Message::AuthenticationKerberosV5 | @@ -406,9 +406,9 @@ impl InnerConnection { fn raw_prepare(&mut self, stmt_name: &str, query: &str) -> Result<(Vec, Vec)> { debug!("preparing query with name `{}`: {}", stmt_name, query); - try!(self.stream.write_message2(|buf| frontend::parse(stmt_name, query, None, buf))); - try!(self.stream.write_message2(|buf| frontend::describe(b'S', stmt_name, buf))); - try!(self.stream.write_message2(|buf| Ok::<(), std_io::Error>(frontend::sync(buf)))); + try!(self.stream.write_message(|buf| frontend::parse(stmt_name, query, None, buf))); + try!(self.stream.write_message(|buf| frontend::describe(b'S', stmt_name, buf))); + try!(self.stream.write_message(|buf| Ok::<(), std_io::Error>(frontend::sync(buf)))); try!(self.stream.flush()); match try!(self.read_message()) { @@ -465,11 +465,11 @@ impl InnerConnection { return DbError::new(fields); } backend::Message::CopyInResponse { .. } => { - try!(self.stream.write_message2(|buf| { + try!(self.stream.write_message(|buf| { frontend::copy_fail("COPY queries cannot be directly executed", buf) })); try!(self.stream - .write_message2(|buf| Ok::<(), std_io::Error>(frontend::sync(buf)))); + .write_message(|buf| Ok::<(), std_io::Error>(frontend::sync(buf)))); try!(self.stream.flush()); } backend::Message::CopyOutResponse { .. } => { @@ -509,7 +509,7 @@ impl InnerConnection { { let info = SessionInfo::new(&self.parameters); - let r = self.stream.write_message2(|buf| { + let r = self.stream.write_message(|buf| { frontend::bind(portal_name, &stmt_name, Some(1), @@ -531,8 +531,8 @@ impl InnerConnection { } } - try!(self.stream.write_message2(|buf| frontend::execute(portal_name, row_limit, buf))); - try!(self.stream.write_message2(|buf| Ok::<(), std_io::Error>(frontend::sync(buf)))); + try!(self.stream.write_message(|buf| frontend::execute(portal_name, row_limit, buf))); + try!(self.stream.write_message(|buf| Ok::<(), std_io::Error>(frontend::sync(buf)))); try!(self.stream.flush()); match try!(self.read_message()) { @@ -587,8 +587,8 @@ impl InnerConnection { } fn close_statement(&mut self, name: &str, type_: u8) -> Result<()> { - try!(self.stream.write_message2(|buf| frontend::close(type_, name, buf))); - try!(self.stream.write_message2(|buf| Ok::<(), std_io::Error>(frontend::sync(buf)))); + try!(self.stream.write_message(|buf| frontend::close(type_, name, buf))); + try!(self.stream.write_message(|buf| Ok::<(), std_io::Error>(frontend::sync(buf)))); try!(self.stream.flush()); let resp = match try!(self.read_message()) { backend::Message::CloseComplete => Ok(()), @@ -798,7 +798,7 @@ impl InnerConnection { fn quick_query(&mut self, query: &str) -> Result>>> { check_desync!(self); debug!("executing query: {}", query); - try!(self.stream.write_message2(|buf| frontend::query(query, buf))); + try!(self.stream.write_message(|buf| frontend::query(query, buf))); try!(self.stream.flush()); let mut result = vec![]; @@ -811,11 +811,11 @@ impl InnerConnection { .collect()); } backend::Message::CopyInResponse { .. } => { - try!(self.stream.write_message2(|buf| { + try!(self.stream.write_message(|buf| { frontend::copy_fail("COPY queries cannot be directly executed", buf) })); try!(self.stream - .write_message2(|buf| Ok::<(), std_io::Error>(frontend::sync(buf)))); + .write_message(|buf| Ok::<(), std_io::Error>(frontend::sync(buf)))); try!(self.stream.flush()); } backend::Message::ErrorResponse { fields } => { @@ -830,7 +830,7 @@ impl InnerConnection { fn finish_inner(&mut self) -> Result<()> { check_desync!(self); - try!(self.stream.write_message2(|buf| Ok::<(), std_io::Error>(frontend::terminate(buf)))); + try!(self.stream.write_message(|buf| Ok::<(), std_io::Error>(frontend::terminate(buf)))); try!(self.stream.flush()); Ok(()) } diff --git a/src/priv_io.rs b/src/priv_io.rs index 483ac40b..e6b64c46 100644 --- a/src/priv_io.rs +++ b/src/priv_io.rs @@ -39,7 +39,7 @@ impl MessageStream { self.stream.get_ref() } - pub fn write_message2(&mut self, f: F) -> Result<(), E> + pub fn write_message(&mut self, f: F) -> Result<(), E> where F: FnOnce(&mut Vec) -> Result<(), E>, E: From { diff --git a/src/rows.rs b/src/rows.rs index 01d6528b..34056ee8 100644 --- a/src/rows.rs +++ b/src/rows.rs @@ -354,8 +354,8 @@ impl<'trans, 'stmt> LazyRows<'trans, 'stmt> { fn execute(&mut self) -> Result<()> { let mut conn = self.stmt.conn().conn.borrow_mut(); - try!(conn.stream.write_message2(|buf| frontend::execute(&self.name, self.row_limit, buf))); - try!(conn.stream.write_message2(|buf| Ok::<(), io::Error>(frontend::sync(buf)))); + try!(conn.stream.write_message(|buf| frontend::execute(&self.name, self.row_limit, buf))); + try!(conn.stream.write_message(|buf| Ok::<(), io::Error>(frontend::sync(buf)))); try!(conn.stream.flush()); conn.read_rows(&mut self.data).map(|more_rows| self.more_rows = more_rows) } diff --git a/src/stmt.rs b/src/stmt.rs index 4660435f..2ba2eee7 100644 --- a/src/stmt.rs +++ b/src/stmt.rs @@ -146,11 +146,11 @@ impl<'conn> Statement<'conn> { break; } backend::Message::CopyInResponse { .. } => { - try!(conn.stream.write_message2(|buf| { + try!(conn.stream.write_message(|buf| { frontend::copy_fail("COPY queries cannot be directly executed", buf) })); try!(conn.stream - .write_message2(|buf| Ok::<(), io::Error>(frontend::sync(buf)))); + .write_message(|buf| Ok::<(), io::Error>(frontend::sync(buf)))); try!(conn.stream.flush()); } backend::Message::CopyOutResponse { .. } => { @@ -297,16 +297,18 @@ impl<'conn> Statement<'conn> { match fill_copy_buf(&mut buf, r, &info) { Ok(0) => break, Ok(len) => { - try!(info.conn.stream.write_message2(|out| frontend::copy_data(&buf[..len], out))); + try!(info + .conn + .stream.write_message(|out| frontend::copy_data(&buf[..len], out))); } Err(err) => { - try!(info.conn.stream.write_message2(|buf| frontend::copy_fail("", buf))); + try!(info.conn.stream.write_message(|buf| frontend::copy_fail("", buf))); try!(info.conn .stream - .write_message2(|buf| Ok::<(), io::Error>(frontend::copy_done(buf)))); + .write_message(|buf| Ok::<(), io::Error>(frontend::copy_done(buf)))); try!(info.conn .stream - .write_message2(|buf| Ok::<(), io::Error>(frontend::sync(buf)))); + .write_message(|buf| Ok::<(), io::Error>(frontend::sync(buf)))); try!(info.conn.stream.flush()); match try!(info.conn.read_message()) { backend::Message::ErrorResponse { .. } => { @@ -323,8 +325,8 @@ impl<'conn> Statement<'conn> { } } - try!(info.conn.stream.write_message2(|buf| Ok::<(), io::Error>(frontend::copy_done(buf)))); - try!(info.conn.stream.write_message2(|buf| Ok::<(), io::Error>(frontend::sync(buf)))); + try!(info.conn.stream.write_message(|buf| Ok::<(), io::Error>(frontend::copy_done(buf)))); + try!(info.conn.stream.write_message(|buf| Ok::<(), io::Error>(frontend::sync(buf)))); try!(info.conn.stream.flush()); let num = match try!(info.conn.read_message()) { @@ -374,10 +376,10 @@ impl<'conn> Statement<'conn> { (format, column_formats) } backend::Message::CopyInResponse { .. } => { - try!(conn.stream.write_message2(|buf| frontend::copy_fail("", buf))); + try!(conn.stream.write_message(|buf| frontend::copy_fail("", buf))); try!(conn.stream - .write_message2(|buf| Ok::<(), io::Error>(frontend::copy_done(buf)))); - try!(conn.stream.write_message2(|buf| Ok::<(), io::Error>(frontend::sync(buf)))); + .write_message(|buf| Ok::<(), io::Error>(frontend::copy_done(buf)))); + try!(conn.stream.write_message(|buf| Ok::<(), io::Error>(frontend::sync(buf)))); try!(conn.stream.flush()); match try!(conn.read_message()) { backend::Message::ErrorResponse { .. } => {